Class: TabsBlock
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- TabsBlock
- Defined in:
- lib/jekyll_bootstrap5_tabs.rb
Overview
Handles the outer tabs %endtabs % Liquid block for Bootstrap 5
Instance Method Summary collapse
- #check_config_boolean(config, _option) ⇒ TrueClass, FalseClass
-
#initialize(tag, args, _) ⇒ TabsBlock
constructor
A new instance of TabsBlock.
- #render(context) ⇒ Object
- #template_path(template_name) ⇒ Object
Constructor Details
#initialize(tag, args, _) ⇒ TabsBlock
Returns a new instance of TabsBlock.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll_bootstrap5_tabs.rb', line 16 def initialize(tag, args, _) super raise SyntaxError, "#{tag} requires name" if args.empty? @logger = PluginMetaLogger.instance.new_logger(self) argv = args.strip.split @tab_name = argv[0] # TODO @tab_name is never used. Should act as a namespace. # Usage can override default and enable pretty-printing, not possible to disable per-tab @pretty_print = false if argv.length > 1 && argv[1].casecmp('pretty').zero? @pretty_print = true @logger.info { "Bootstrap tab pretty-printing is enabled for #{@tab_name}" } end end |
Instance Method Details
#check_config_boolean(config, _option) ⇒ TrueClass, FalseClass
37 38 39 40 41 42 43 44 45 |
# File 'lib/jekyll_bootstrap5_tabs.rb', line 37 def check_config_boolean(config, _option) = config['jekyll_bootstrap5_tabs'] return false if .nil? hash = .detect { |opt| opt["pretty"] } @logger.debug { "tabs_options = #{}" } @logger.debug { "hash = #{hash}" } !hash.nil? && hash['pretty'] end |
#render(context) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jekyll_bootstrap5_tabs.rb', line 52 def render(context) site = context.registers[:site] # Set the pretty-print option for the Slim engine # Global configuration provides the default value of @pretty_print if check_config_boolean(site.config, 'pretty') @pretty_print = true @logger.info { "Bootstrap tab pretty-printing is enabled by default for the entire Jekyll site." } end @environment = context.environments.first # Has type Jekyll::Drops::UnifiedPayloadDrop @logger.debug { "TabsBlock.render: @environment = '#{@environment}'" } super template_file_path = template_path(DEFAULT_TEMPLATE) Slim::Engine. :pretty => @pretty_print template = Slim::Template.new(template_file_path) template.render(self) end |
#template_path(template_name) ⇒ Object
47 48 49 50 |
# File 'lib/jekyll_bootstrap5_tabs.rb', line 47 def template_path(template_name) dir = File.dirname(__FILE__) File.join(dir, template_name.to_s) end |