Class: Fugleman::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/fugleman/namespace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, path, obj) ⇒ Namespace

Returns a new instance of Namespace.



6
7
8
9
10
# File 'lib/fugleman/namespace.rb', line 6

def initialize context, path, obj
  @context = context
  @path = path
  @obj = obj
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/fugleman/namespace.rb', line 4

def path
  @path
end

Instance Method Details

#checkbox(name, opts = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/fugleman/namespace.rb', line 17

def checkbox name, opts={}
  input_tag :checkbox, name, '', {
    placeholder: nil, 
    class: nil,
    value: 'true',
    checked: value(name) }.merge(opts)
end

#full_name(something) ⇒ Object



30
31
32
# File 'lib/fugleman/namespace.rb', line 30

def full_name something
  @path.to_s + "[#{something}]"
end

#input_tag(type, name, opts = {}) ⇒ Object



12
13
14
15
# File 'lib/fugleman/namespace.rb', line 12

def input_tag type, name, opts={}
  opts = {value: value(name)}.merge(opts)
  @context.input_tag type, full_name(name), opts
end

#textarea(name, opts = {}) ⇒ Object



24
25
26
27
28
# File 'lib/fugleman/namespace.rb', line 24

def textarea name, opts={}
  @context. :textarea, 
    @context.h(value(name)), {
      name: full_name(name) }.merge(opts)
end

#value(name) ⇒ Object



33
34
35
36
# File 'lib/fugleman/namespace.rb', line 33

def value name
  return nil unless @obj
  return @obj.send(name)
end