Class: JekyllBlocker::Block
- Inherits:
-
Object
- Object
- JekyllBlocker::Block
- Defined in:
- lib/jekyll-blocker/block.rb
Constant Summary collapse
- ALLOWED_TAGS =
%w(assign break capture case comment continue cycle decrement for if ifchanged increment raw tablerow unless highlight link post_url)
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(content: "", data: {}) ⇒ Block
constructor
A new instance of Block.
- #render(instance_data, context) ⇒ Object
Constructor Details
#initialize(content: "", data: {}) ⇒ Block
Returns a new instance of Block.
9 10 11 12 |
# File 'lib/jekyll-blocker/block.rb', line 9 def initialize(content: "", data: {}) @content = content.instance_of?(String) ? content : "" @data = data.instance_of?(Hash) ? data : {} end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/jekyll-blocker/block.rb', line 3 def content @content end |
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/jekyll-blocker/block.rb', line 3 def data @data end |
Instance Method Details
#render(instance_data, context) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jekyll-blocker/block.rb', line 14 def render(instance_data, context) _context = Liquid::Context.new(context.environments.dup, {}, context.registers) data.each do |key, value| temp = instance_data.key?(key) ? instance_data[key] : value["value"] case value["type"] when "text", "richtext", "html" do temp = Liquid::Template.parse(temp).render(context) end when "image" temp['src'] = '/uploads/images/' + temp['src'] when "file" temp = '/uploads/files/' + temp when "markdown" do temp = Liquid::Template.parse(temp).render(context) end temp = Kramdown::Document.new(temp, input: 'GFM').to_html end _context[key] = temp end template = Liquid::Template.parse(@content) template.render(_context) end |