Class: Deface::DSL::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/deface/dsl/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Context

Returns a new instance of Context.



4
5
6
7
# File 'lib/deface/dsl/context.rb', line 4

def initialize(name)
  @name = name
  @options = {}
end

Class Method Details

.define_action_method(action_name) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/deface/dsl/context.rb', line 22

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

.define_source_method(source_name) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/deface/dsl/context.rb', line 32

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

Instance Method Details

#attributes(values) ⇒ Object



54
55
56
# File 'lib/deface/dsl/context.rb', line 54

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

#closing_selector(selector) ⇒ Object



46
47
48
# File 'lib/deface/dsl/context.rb', line 46

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

#create_overrideObject



9
10
11
12
13
14
15
16
# File 'lib/deface/dsl/context.rb', line 9

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

  Deface::Override.new(options)
end

#disabledObject



62
63
64
# File 'lib/deface/dsl/context.rb', line 62

def disabled
  @options[:disabled] = true
end

#enabledObject



58
59
60
# File 'lib/deface/dsl/context.rb', line 58

def enabled
  @options[:disabled] = false
end

#namespacedObject



66
67
68
# File 'lib/deface/dsl/context.rb', line 66

def namespaced
  @options[:namespaced] = true
end

#original(markup) ⇒ Object



42
43
44
# File 'lib/deface/dsl/context.rb', line 42

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

#sequence(value) ⇒ Object



50
51
52
# File 'lib/deface/dsl/context.rb', line 50

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

#virtual_path(name) ⇒ Object



18
19
20
# File 'lib/deface/dsl/context.rb', line 18

def virtual_path(name)
  @virtual_path = name
end