Sha256: 6e91ea0e2b91faf2264f47ad622f9a5f9471dcb6f26cbbd985b7b48aa646ed45

Contents?: true

Size: 1.62 KB

Versions: 28

Compression:

Stored size: 1.62 KB

Contents

module Deface
  module DSL
    class Context
      def initialize(name)
        @name = name
        @options = {}
      end

      def create_override
        options = {
          :name => @name, 
          :virtual_path => @virtual_path,
        }.merge(@action || {}).merge(@source || {}).merge(@options)

        Deface::Override.new(options)
      end

      def virtual_path(name)
        @virtual_path = name
      end

      def self.define_action_method(action_name)
        define_method(action_name) do |selector|
          if @action.present?
            Rails.logger.error "\e[1;32mDeface: [WARNING]\e[0m Multiple action methods have been called. The last one will be used."
          end

          @action = { action_name => selector }
        end
      end

      def self.define_source_method(source_name)
        define_method(source_name) do |value|
          if @source.present?
            Rails.logger.error "\e[1;32mDeface: [WARNING]\e[0m Multiple source methods have been called. The last one will be used."
          end

          @source = { source_name => value }
        end
      end

      def original(markup)
        @options[:original] = markup
      end

      def closing_selector(selector)
        @options[:closing_selector] = selector
      end

      def sequence(value)
        @options[:sequence] = value
      end

      def attributes(values)
        @options[:attributes] = values
      end

      def enabled
        @options[:disabled] = false
      end

      def disabled
        @options[:disabled] = true
      end

      def namespaced
        @options[:namespaced] = true
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
deface-1.9.0 lib/deface/dsl/context.rb
deface-1.8.2 lib/deface/dsl/context.rb
deface-1.8.1 lib/deface/dsl/context.rb
deface-1.8.0 lib/deface/dsl/context.rb
deface-1.7.0 lib/deface/dsl/context.rb
deface-1.6.2 lib/deface/dsl/context.rb
deface-1.6.1 lib/deface/dsl/context.rb
deface-1.6.0 lib/deface/dsl/context.rb
deface-1.5.3 lib/deface/dsl/context.rb
deface-1.5.2 lib/deface/dsl/context.rb
deface-1.5.1 lib/deface/dsl/context.rb
deface-1.5.0 lib/deface/dsl/context.rb
deface-1.4.0 lib/deface/dsl/context.rb
deface-1.3.2 lib/deface/dsl/context.rb
deface-1.3.1 lib/deface/dsl/context.rb
deface-1.3.0 lib/deface/dsl/context.rb
deface-1.2.0 lib/deface/dsl/context.rb
deface-1.1.0 lib/deface/dsl/context.rb
deface-1.0.2 lib/deface/dsl/context.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/deface-1.0.1/lib/deface/dsl/context.rb