Class: Hicube::Liquid::Tags::ContentTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Hicube::Liquid::Tags::ContentTag
- Defined in:
- lib/hicube/liquid/tags/content.rb
Instance Method Summary collapse
-
#initialize(tag_name, variables, tokens) ⇒ ContentTag
constructor
A new instance of ContentTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, variables, tokens) ⇒ ContentTag
Returns a new instance of ContentTag.
6 7 8 9 |
# File 'lib/hicube/liquid/tags/content.rb', line 6 def initialize(tag_name, variables, tokens) @variables = variables super end |
Instance Method Details
#render(context) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hicube/liquid/tags/content.rb', line 11 def render(context) return "<div class=\"alert alert-danger\" role=\"alert\">Supply page and content names in content_tag</div>" if @variables.split(" ").count < 2 @page = Hicube::Page.unscoped.find(@variables.split(" ").first) @content = @page.content.find(@variables.split(" ").last) "<div class=\"editable\" data-type=\"wysihtml5\" data-name=\"content[body]\" data-showbuttons=\"bottom\" data-url=\"/hicube/pages/#{@page.slug}/contents/#{@content.slug}\">#{@content.body}</div>\n" rescue if @page.nil? # page is not spelt correct return "<div class=\"alert alert-danger\" role=\"alert\">Oh Snap! Page not found.</div>" else # return content with alert div, so that new content can be created return "<div class=\"editable\" data-type=\"wysihtml5\" data-name=\"content[body]\" data-showbuttons=\"bottom\" data-url=\"/hicube/pages/#{@page.slug}/contents/#{@variables.split(" ").last}\"><div class=\"alert alert-warning\" role=\"alert\">Content not found. Create new content...</div></div>\n" end end |