Sha256: 87de8fc9aff220b46161efc8fcedd09d110db7acdf2dd848c24292e7ef70906e

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Underworld
  module Liquid
    class Tag < ::Liquid::Tag

      attr_reader :arguments, :params

      # This method produce the `tag_name` DSL which is mandatory for
      # each tag and defines the tag name that the tag class should be
      # registered with
      def self.tag_name(name)
        @@name = name
      end

      def self.name
        @@name
      end

      def self.argument(options)
        raise ArgumentError.new "'name' is mandatory for argument in '#{self.class.name}'" if options[:name].nil?

        @arguments ||= []
        @arguments << options
      end

      def initialize(name, args, options)
        super

        if !arguments.empty? && (args.nil? || args.empty?)
            count = arguments.length
            raise ArgumentError.new "'#{count}' argument(s) is/are needed for '#{self.class.name}' tag."
        end

        @direction   = ::Underworld::I18n.direction(::I18n.locale)

        @args = args.split(',').map do |x|
          x.strip.tr('""', '').tr("''", '')
        end

        @params = {}

        arguments.each_with_index do |arg, index|
          @params[arg[:name]] = @args.fetch(index, arg[:default])
        end
      end

      def arguments
        @arguments ||= []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
underworld-1.0.0 lib/underworld/liquid/tag.rb