Class: Component::Cell::Dynamic

Inherits:
Trailblazer::Cell
  • Object
show all
Includes:
ActionView::Helpers::ActiveModelHelper, ActionView::Helpers::ActiveModelInstanceTag, ActionView::Helpers::AssetTagHelper, ActionView::Helpers::AssetUrlHelper, ActionView::Helpers::AtomFeedHelper, ActionView::Helpers::CacheHelper, ActionView::Helpers::CaptureHelper, ActionView::Helpers::CspHelper, ActionView::Helpers::CsrfHelper, ActionView::Helpers::DateHelper, ActionView::Helpers::DebugHelper, ActionView::Helpers::FormHelper, ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::NumberHelper, ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::RecordTagHelper, ActionView::Helpers::SanitizeHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, ActionView::Helpers::TranslationHelper, ActionView::Helpers::UrlHelper, Basemate::Ui::Core::ApplicationHelper, Cell::Haml, Shared::Utils::ToCell
Defined in:
app/concepts/component/cell/dynamic.rb

Instance Method Summary collapse

Methods included from Basemate::Ui::Core::ApplicationHelper

#render_component, #render_page, #responder_for

Constructor Details

#initialize(model = nil, options = {}) ⇒ Dynamic

Returns a new instance of Dynamic.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/concepts/component/cell/dynamic.rb', line 36

def initialize(model=nil, options={})
  super
  @component_config = options.except(:context, :children, :url_params)
  @url_params = options[:url_params].except(:action, :controller, :component_key)
  @component_key = options[:component_key]
  @children_cells = {}
  @controller_context = context[:controller_context]
  @argument = model
  @static = false
  @nodes = {}
  @cells = {}
  generate_component_name
  generate_children_cells
  set_tag_attributes
  setup
end

Instance Method Details

#component_idObject



95
96
97
# File 'app/concepts/component/cell/dynamic.rb', line 95

def component_id
  options[:id] ||= nil
end

#components(&block) ⇒ Object



109
110
111
112
113
114
115
# File 'app/concepts/component/cell/dynamic.rb', line 109

def components(&block)
  @nodes = ::Component::Utils::ComponentNode.build(self, &block)

  @nodes.each do |key, node|
    @cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"])
  end
end

#js_action(name, arguments) ⇒ Object



99
100
101
102
103
# File 'app/concepts/component/cell/dynamic.rb', line 99

def js_action name, arguments
  argumentString = arguments.join('", "')
  argumentString = '"' + argumentString + '"'
  [name, '(', argumentString, ')'].join("")
end


105
106
107
# File 'app/concepts/component/cell/dynamic.rb', line 105

def navigate_to path
  js_action("navigateTo", [path])
end

#partial(&block) ⇒ Object



117
118
119
# File 'app/concepts/component/cell/dynamic.rb', line 117

def partial(&block)
  ::Component::Utils::ComponentNode.build(self, &block)
end

#render_childrenObject



77
78
79
# File 'app/concepts/component/cell/dynamic.rb', line 77

def render_children
  render(view: :children)
end

#render_content(&block) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/concepts/component/cell/dynamic.rb', line 81

def render_content(&block)
  if respond_to? :prepare
    prepare
  end
  if respond_to? :response
    response &block
      render :response
  else
    render do
      render_children
    end
  end
end

#setupObject



53
54
55
# File 'app/concepts/component/cell/dynamic.rb', line 53

def setup
  true
end

#show(&block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/concepts/component/cell/dynamic.rb', line 57

def show(&block)
  if respond_to? :prepare
    prepare
  end
  if respond_to? :response
    response &block
    if @static
      render :response
    else
      render :response_dynamic
    end
  else
    if @static
      render(view: :static, &block)
    else
      render(view: :dynamic, &block)
    end
  end
end