module Jekyll::ComponentBase
Attributes
content[RW]
props[RW]
Public Class Methods
new(tag_name, markup, tokens)
click to toggle source
Calls superclass method
# File lib/jekyll/spark/base.rb, line 16 def initialize(tag_name, markup, tokens) super @attributes = {} @context = false @context_name = self.name.to_s.gsub("::", "_").downcase @content = '' @default_selector_attr = [] @props = Hash.new @site = false if markup =~ /(#{Liquid::QuotedFragment}+)?/ # Parse parameters # Source: https://gist.github.com/jgatjens/8925165 markup.scan(Liquid::TagAttributes) do |key, value| @attributes[key] = Liquid::Expression.parse(value) end end end
Public Instance Methods
blank?()
click to toggle source
blank? Description: Override's Liquid's default blank checker. This allows for templates to be used without passing inner content.
# File lib/jekyll/spark/base.rb, line 39 def blank? false end
render(context)
click to toggle source
Calls superclass method
# File lib/jekyll/spark/base.rb, line 105 def render(context) @context = context @site = @context.registers[:site] @content = super serialize_data output = template(context) if (output.instance_of?(String)) output = Liquid::Template.parse(output).render() output = @@compressor.compress(unindent(output)) else output = "" end return output end
selector_data_props(attr = @attributes)
click to toggle source
# File lib/jekyll/spark/base.rb, line 54 def selector_data_props(attr = @attributes) template = "" attr.keys.each { |key| if key.include? "data" template += "#{key.gsub("_", "-")}='#{@props[key]}' " end } return template end
selector_default_props(attr = @default_selector_attr)
click to toggle source
# File lib/jekyll/spark/base.rb, line 43 def selector_default_props(attr = @default_selector_attr) template = "" attr.each { |prop| if @props.key?(prop) template += "#{prop}='#{@props[prop]}' " end } return template end
selector_props(attr = @default_selector_attr)
click to toggle source
# File lib/jekyll/spark/base.rb, line 65 def selector_props(attr = @default_selector_attr) template = "" template += selector_data_props template += selector_default_props(attr) return template end
serialize_data()
click to toggle source
# File lib/jekyll/spark/base.rb, line 77 def serialize_data data = Hash.new @attributes["children"] = @content @attributes["content"] = @content if @attributes.length @attributes.each do |key, value| if @context value = @context.evaluate(value) end data[key] = value end end return set_props(data) end
set_props(props = Hash.new)
click to toggle source
# File lib/jekyll/spark/base.rb, line 73 def set_props(props = Hash.new) @props = @props.merge(props) end
template(context = @context)
click to toggle source
# File lib/jekyll/spark/base.rb, line 122 def template(context = @context) return context end
unindent(content)
click to toggle source
# File lib/jekyll/spark/base.rb, line 93 def unindent(content) # Remove initial whitespace content.gsub!(/\A^\s*\n/, "") # Remove indentations if content =~ %r!^\s*!m indentation = Regexp.last_match(0).length content.gsub!(/^\ {#{indentation}}/, "") end return content end