Class: LcpRuby::Dsl::ViewGroupBuilder

Inherits:
Object
  • Object
show all
Includes:
SourceLocationCapture
Defined in:
lib/lcp_ruby/dsl/view_group_builder.rb

Instance Method Summary collapse

Methods included from SourceLocationCapture

capture_source_loc

Constructor Details

#initialize(name) ⇒ ViewGroupBuilder

Returns a new instance of ViewGroupBuilder.



8
9
10
11
12
13
14
15
16
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 8

def initialize(name)
  @name = name.to_s
  @model_name = nil
  @primary_value = nil
  @navigation_hash = nil
  @breadcrumb_value = nil
  @switcher_value = nil
  @views = []
end

Instance Method Details



39
40
41
42
43
44
45
46
47
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 39

def breadcrumb(value = nil, relation: nil)
  if value == false
    @breadcrumb_value = false
  elsif relation
    @breadcrumb_value = { "relation" => relation.to_s }
  elsif !value.nil?
    raise ArgumentError, "breadcrumb expects `false` or `relation:` keyword, got: #{value.inspect}"
  end
end

#model(value) ⇒ Object



18
19
20
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 18

def model(value)
  @model_name = value.to_s
end


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 26

def navigation(value = nil, menu: nil, position: nil, auto_append: nil)
  if value == false
    @navigation_hash = false
  elsif menu || !position.nil? || !auto_append.nil?
    @navigation_hash = {}
    @navigation_hash["menu"] = menu.to_s if menu
    @navigation_hash["position"] = position if position
    @navigation_hash["auto_append"] = auto_append unless auto_append.nil?
  else
    raise ArgumentError, "navigation expects `false`, `menu:`, `position:`, or `auto_append:` keyword, got: #{value.inspect}"
  end
end

#primary(value) ⇒ Object



22
23
24
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 22

def primary(value)
  @primary_value = value.to_s
end

#switcher(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 49

def switcher(*args)
  if args.length == 1 && args.first == false
    @switcher_value = false
  elsif args.length == 1 && args.first == :auto
    @switcher_value = "auto"
  elsif args.length == 1 && args.first.is_a?(Array)
    @switcher_value = args.first.map(&:to_s)
  else
    @switcher_value = args.map(&:to_s)
  end
end

#to_hashObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 71

def to_hash
  hash = {
    "view_group" => {
      "name" => @name
    }
  }
  vg = hash["view_group"]
  vg["model"] = @model_name if @model_name
  vg["primary"] = @primary_value if @primary_value
  vg["navigation"] = @navigation_hash unless @navigation_hash.nil?
  vg["breadcrumb"] = @breadcrumb_value unless @breadcrumb_value.nil?
  vg["switcher"] = @switcher_value unless @switcher_value.nil?
  vg["views"] = @views unless @views.empty?
  hash
end

#to_yamlObject



87
88
89
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 87

def to_yaml
  to_hash.to_yaml
end

#view(page_name, label: nil, icon: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/lcp_ruby/dsl/view_group_builder.rb', line 61

def view(page_name, label: nil, icon: nil)
  view_hash = { "page" => page_name.to_s }
  if label
    view_hash["label"] = label
    view_hash["_label_source_loc"] = capture_source_loc
  end
  view_hash["icon"] = icon.to_s if icon
  @views << view_hash
end