Sha256: 1a657e68a0dbac857581d13ff3030a5fe91273029c0f14ed6a9bd365b0adcce3

Contents?: true

Size: 985 Bytes

Versions: 12

Compression:

Stored size: 985 Bytes

Contents

module PufferPages
  module Liquid
    module Tags

      class Javascripts < ::Liquid::Tag
        Syntax = /^(#{::Liquid::QuotedFragment}+)/

        def initialize(tag_name, markup, tokens)
          if markup =~ Syntax
            @paths = variables_from_string(markup)
          else
            raise SyntaxError.new("Syntax Error in 'javascripts' - Valid syntax: javascripts path [, path, path ...]")
          end

          super
        end

        def render(context)
          paths = @paths.map {|path| "'#{context[path]}'" }.join(', ')
          context.registers[:tracker].register "<%= javascript_include_tag #{paths} %>"
        end

      private

        def variables_from_string(markup)
          markup.split(',').map do |var|
          var.strip =~ /\s*(#{::Liquid::QuotedFragment})\s*/
          $1 ? $1 : nil
          end.compact
        end

      end

    end
  end
end

Liquid::Template.register_tag('javascripts', PufferPages::Liquid::Tags::Javascripts)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puffer_pages-0.0.19 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.18 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.17 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.16 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.15 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.14 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.13 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.12 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.11 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.10 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.9 lib/puffer_pages/liquid/tags/javascripts.rb
puffer_pages-0.0.8 lib/puffer_pages/liquid/tags/javascripts.rb