Class: JekyllSupport::JekyllBlock
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- JekyllSupport::JekyllBlock
- Includes:
- JekyllSupportError
- Defined in:
- lib/block/jekyll_plugin_support_block.rb,
lib/jekyll_plugin_support.rb
Overview
Base class for Jekyll block tags
Direct Known Subclasses
Instance Attribute Summary collapse
-
#argument_string ⇒ Object
readonly
Returns the value of attribute argument_string.
-
#helper ⇒ Object
readonly
Returns the value of attribute helper.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Liquid::Block subclasses do not render if there is no content within the tag This override fixes that.
- #initialize(tag_name, markup, parse_context) ⇒ void constructor
-
#render(liquid_context) ⇒ String
Method prescribed by the Jekyll plugin lifecycle.
-
#render_impl(text) ⇒ String
Jekyll plugins should override this method, not render, so they can be tested more easily.
- #set_error_context ⇒ Object
Methods included from JekyllSupportError
#exit_without_stack_trace, #format_error_message, #maybe_reraise_error, #remove_ansi_color, #warn_short_trace
Constructor Details
#initialize(tag_name, markup, parse_context) ⇒ void
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 17 def initialize(tag_name, markup, parse_context) super @tag_name = tag_name @argument_string = markup.to_s # Vars in plugin parameters cannot be replaced yet @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config) @logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." } @helper = JekyllPluginHelper.new tag_name, markup, @logger, respond_to?(:no_arg_parsing) @error_name = "#{tag_name.camelcase(:upper)}Error" JekyllSupport::CustomError.factory @error_name end |
Instance Attribute Details
#argument_string ⇒ Object (readonly)
Returns the value of attribute argument_string.
6 7 8 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 6 def argument_string @argument_string end |
#helper ⇒ Object (readonly)
Returns the value of attribute helper.
6 7 8 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 6 def helper @helper end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
6 7 8 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 6 def line_number @line_number end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 6 def logger @logger end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 6 def page @page end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
6 7 8 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 6 def site @site end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 6 def text @text end |
Instance Method Details
#blank? ⇒ Boolean
Liquid::Block subclasses do not render if there is no content within the tag This override fixes that
31 32 33 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 31 def blank? false end |
#render(liquid_context) ⇒ String
Method prescribed by the Jekyll plugin lifecycle. Defines @config, @envs, @mode, @page and @site
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 38 def render(liquid_context) @helper.liquid_context = JekyllSupport.inject_vars @logger, liquid_context text = super # Liquid variable values in content are looked up and substituted @envs = liquid_context.environments.first @page = liquid_context.registers[:page] # hash @scopes = liquid_context.scopes @site = liquid_context.registers[:site] @config = @site.config @tag_config = @config[@tag_name] @jps = @config['jekyll_plugin_support'] @pry_on_standard_error = @jps['pry_on_standard_error'] || false if @jps set_error_context @layout = @envs[:layout] @paginator = @envs[:paginator] @theme = @envs[:theme] env = @config['env'] @mode = env&.key?('JEKYLL_ENV') ? env['JEKYLL_ENV'] : 'development' @helper.reinitialize @markup.strip @attribution = @helper.parameter_specified?('attribution') || false unless @no_arg_parsing @logger.debug { "@keys_values='#{@keys_values}'" } markup = JekyllSupport.lookup_liquid_variables liquid_context, @argument_string @helper.reinitialize markup render_impl(text) rescue StandardError => e e.shorten_backtrace @logger.error { "#{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{@tag_name} - #{e.}" } binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger raise e if @die_on_standard_error <<~END_MSG <div class='standard_error'> #{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{@tag_name}: #{e.} </div> END_MSG end |
#render_impl(text) ⇒ String
Jekyll plugins should override this method, not render, so they can be tested more easily. The following variables are predefined:
@argument_string, @config, @envs, @helper, @layout, @logger, @mode, @page, @paginator, @site, @tag_name and @theme
88 89 90 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 88 def render_impl(text) text end |
#set_error_context ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/block/jekyll_plugin_support_block.rb', line 92 def set_error_context return unless Object.const_defined? @error_name error_class = Object.const_get @error_name error_class.class_variable_set(:@@argument_string, @argument_string) error_class.class_variable_set(:@@line_number, @line_number) error_class.class_variable_set(:@@path, @page['path']) error_class.class_variable_set(:@@tag_name, @tag_name) end |