Sha256: 05c1da32de9ee3be0553b9ce5d278084e9e3d47ee08db31ace0ba494f27ee271

Contents?: true

Size: 1.4 KB

Versions: 11

Compression:

Stored size: 1.4 KB

Contents

module Hicube
  module Liquid
    module Tags
      class ContentTag < ::Liquid::Tag

        def initialize(tag_name, variables, tokens)
          @variables = variables
          super
        end

        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
      end

      ::Liquid::Template.register_tag('content_tag', ContentTag)

    end
  end
end 

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hicube-0.0.11 lib/hicube/liquid/tags/content.rb
hicube-0.0.10 lib/hicube/liquid/tags/content.rb
hicube-0.0.9 lib/hicube/liquid/tags/content.rb
hicube-0.0.8 lib/hicube/liquid/tags/content.rb
hicube-0.0.7 lib/hicube/liquid/tags/content.rb
hicube-0.0.6 lib/hicube/liquid/tags/content.rb
hicube-0.0.5 lib/hicube/liquid/tags/content.rb
hicube-0.0.4 lib/hicube/liquid/tags/content.rb
hicube-0.0.3 lib/hicube/liquid/tags/content.rb
hicube-0.0.2 lib/hicube/liquid/tags/content.rb
hicube-0.0.1 lib/hicube/liquid/tags/content.rb