class Shortcode::Tag
Attributes
configuration[R]
Public Class Methods
new(name, configuration, attributes=[], content="", additional_attributes=nil)
click to toggle source
# File lib/shortcode/tag.rb, line 3 def initialize(name, configuration, attributes=[], content="", additional_attributes=nil) @name = name.downcase @configuration = configuration @binding = Shortcode::TemplateBinding.new(@name, @configuration, attributes, content, additional_attributes) end
Public Instance Methods
markup()
click to toggle source
# File lib/shortcode/tag.rb, line 13 def markup template = first_priority_template template = second_priority_template if template.nil? return template unless template.nil? raise Shortcode::TemplateNotFound, "No template found for #{@name} in configuration or files" end
render()
click to toggle source
# File lib/shortcode/tag.rb, line 20 def render render_template end
Private Instance Methods
first_priority_template()
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/shortcode/tag.rb, line 43 def first_priority_template configuration.check_config_templates_first ? markup_from_config : markup_from_file end
markup_from_config()
click to toggle source
# File lib/shortcode/tag.rb, line 58 def markup_from_config configuration.templates[@name.to_sym] end
markup_from_file()
click to toggle source
# File lib/shortcode/tag.rb, line 51 def markup_from_file template_files.each do |path| return File.read(path) if File.file? path end nil end
render_template()
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/shortcode/tag.rb, line 29 def render_template case configuration.template_parser when :erb ERB.new(markup).result(@binding.expose_binding) when :haml Haml::Engine.new(markup).render(@binding) when :slim Slim::Template.new { markup }.render(@binding) else raise Shortcode::TemplateParserNotSupported, configuration.template_parser end end
second_priority_template()
click to toggle source
# File lib/shortcode/tag.rb, line 47 def second_priority_template configuration.check_config_templates_first ? markup_from_file : markup_from_config end
template_files()
click to toggle source
# File lib/shortcode/tag.rb, line 62 def template_files template_paths.map do |filename| File.join configuration.template_path, filename end end
template_paths()
click to toggle source
# File lib/shortcode/tag.rb, line 68 def template_paths ["#{@name}.html.#{configuration.template_parser}", "#{@name}.#{configuration.template_parser}"] end