├── .gitignore ├── LICENSE ├── README.md ├── _plugins └── jekyll-code-tabs.rb ├── docs └── screencap.gif ├── jekyll-code-tabs.gemspec └── lib ├── jekyll-code-tabs.rb └── jekyll-code-tabs └── version.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Brett Fowle (https://clustergarage.io 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jekyll-code-tabs 2 | 3 | > 💎 Separate language snippets with fenced code tabs for documentation pages 4 | 5 | ## Usage 6 | 7 | ```` 8 | {% codetabs %} 9 | 10 | {% codetab C %} 11 | ```c 12 | printf("Hello, world!"); 13 | ``` 14 | {% endcodetab %} 15 | 16 | {% codetab Go %} 17 | ```go 18 | fmt.Println("Hello, world!") 19 | ``` 20 | {% endcodetab %} 21 | 22 | {% codetab Python %} 23 | ```python 24 | print("Hello, world!") 25 | ``` 26 | {% endcodetab %} 27 | 28 | {% endcodetabs %} 29 | ```` 30 | 31 | This will create a tabbed-view (hardcoded to UIkit classes for now) that will 32 | allow the user to toggle between content. 33 | 34 | ![alt 35 | text](https://raw.githubusercontent.com/clustergarage/jekyll-code-tabs/master/docs/screencap.gif) 36 | -------------------------------------------------------------------------------- /_plugins/jekyll-code-tabs.rb: -------------------------------------------------------------------------------- 1 | require_relative "../lib/jekyll-code-tabs" 2 | -------------------------------------------------------------------------------- /docs/screencap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clustergarage/jekyll-code-tabs/584357e14663056b718925f9de022da2a3907792/docs/screencap.gif -------------------------------------------------------------------------------- /jekyll-code-tabs.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path("../lib", __FILE__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | require "jekyll-code-tabs/version" 4 | Gem::Specification.new do |spec| 5 | spec.name = "jekyll-code-tabs" 6 | spec.summary = "Fenced code tabs for Jekyll" 7 | spec.description = "Separate language snippets with fenced code tabs for documentation pages" 8 | spec.version = Jekyll::CodeTabs::VERSION 9 | spec.authors = ["Brett Fowle"] 10 | spec.email = ["brettfowle@gmail.com"] 11 | spec.homepage = "https://github.com/clustergarage/jekyll-code-tabs" 12 | spec.licenses = ["MIT"] 13 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) } 14 | spec.require_paths = ["lib"] 15 | spec.add_dependency "jekyll", ">= 3.0", "< 5.0" 16 | spec.add_development_dependency "rake", "~> 13.0.1" 17 | spec.add_development_dependency "rspec", "~> 3.5" 18 | spec.add_development_dependency "rubocop", "~> 0.52" 19 | end 20 | -------------------------------------------------------------------------------- /lib/jekyll-code-tabs.rb: -------------------------------------------------------------------------------- 1 | require "erb" 2 | require 'securerandom' 3 | require_relative "jekyll-code-tabs/version" 4 | 5 | module Jekyll 6 | module CodeTabs 7 | class CodeTabsBlock < Liquid::Block 8 | def render(context) 9 | environment = context.environments.first 10 | environment['codetabs'] = {} # reset each time 11 | super 12 | 13 | uuid = SecureRandom.uuid 14 | template = ERB.new <<-EOF 15 | 20 | 21 | 26 | EOF 27 | template.result(binding) 28 | end 29 | end 30 | 31 | class CodeTabBlock < Liquid::Block 32 | alias_method :render_block, :render 33 | 34 | def initialize(tag_name, markup, tokens) 35 | super 36 | if markup == "" 37 | raise SyntaxError.new("No toggle name given in #{tag_name} tag") 38 | end 39 | @toggle = markup.strip 40 | end 41 | 42 | def render(context) 43 | site = context.registers[:site] 44 | converter = site.find_converter_instance(::Jekyll::Converters::Markdown) 45 | environment = context.environments.first 46 | environment['codetabs'] ||= {} 47 | environment['codetabs'][@toggle] = converter.convert(render_block(context)) 48 | end 49 | end 50 | end 51 | end 52 | 53 | Liquid::Template.register_tag("codetab", Jekyll::CodeTabs::CodeTabBlock) 54 | Liquid::Template.register_tag("codetabs", Jekyll::CodeTabs::CodeTabsBlock) 55 | -------------------------------------------------------------------------------- /lib/jekyll-code-tabs/version.rb: -------------------------------------------------------------------------------- 1 | module Jekyll 2 | module CodeTabs 3 | VERSION = "1.2.0".freeze 4 | end 5 | end 6 | --------------------------------------------------------------------------------