matestack-ui-core 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of matestack-ui-core might be problematic. Click here for more details.

Files changed (129) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +230 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/config/basemate_ui_core_manifest.js +2 -0
  6. data/app/assets/javascripts/basemate/ui/core/application.js +15 -0
  7. data/app/assets/stylesheets/basemate/ui/core/application.css +15 -0
  8. data/app/concepts/absolute/cell/absolute.rb +17 -0
  9. data/app/concepts/absolute/view/absolute.haml +3 -0
  10. data/app/concepts/action/cell/action.rb +52 -0
  11. data/app/concepts/action/js/action.js +49 -0
  12. data/app/concepts/action/view/action.haml +3 -0
  13. data/app/concepts/app/cell/app.rb +76 -0
  14. data/app/concepts/app/js/app.js +27 -0
  15. data/app/concepts/app/js/store.js +71 -0
  16. data/app/concepts/app/utils/app_node.rb +53 -0
  17. data/app/concepts/app/view/app.haml +4 -0
  18. data/app/concepts/async/cell/async.rb +10 -0
  19. data/app/concepts/async/js/async.js +57 -0
  20. data/app/concepts/async/view/async.haml +2 -0
  21. data/app/concepts/br/cell/br.rb +5 -0
  22. data/app/concepts/br/view/br.haml +5 -0
  23. data/app/concepts/button/cell/button.rb +5 -0
  24. data/app/concepts/button/view/button.haml +7 -0
  25. data/app/concepts/component/cell/dynamic.rb +226 -0
  26. data/app/concepts/component/cell/static.rb +16 -0
  27. data/app/concepts/component/js/anonym-dynamic-component.js +10 -0
  28. data/app/concepts/component/js/component.js +60 -0
  29. data/app/concepts/component/utils/component_node.rb +69 -0
  30. data/app/concepts/component/view/children.haml +2 -0
  31. data/app/concepts/component/view/dynamic.haml +6 -0
  32. data/app/concepts/component/view/dynamic_without_rerender.haml +2 -0
  33. data/app/concepts/component/view/response.haml +2 -0
  34. data/app/concepts/component/view/response_dynamic.haml +7 -0
  35. data/app/concepts/component/view/response_dynamic_without_rerender.haml +3 -0
  36. data/app/concepts/component/view/static.haml +1 -0
  37. data/app/concepts/core/js/core.js +27 -0
  38. data/app/concepts/core/js/event-hub.js +5 -0
  39. data/app/concepts/div/cell/div.rb +6 -0
  40. data/app/concepts/div/view/div.haml +3 -0
  41. data/app/concepts/footer/cell/footer.rb +5 -0
  42. data/app/concepts/footer/view/footer.haml +3 -0
  43. data/app/concepts/form/cell/form.rb +71 -0
  44. data/app/concepts/form/cell/inline.rb +9 -0
  45. data/app/concepts/form/cell/input.rb +74 -0
  46. data/app/concepts/form/cell/select.rb +73 -0
  47. data/app/concepts/form/cell/submit.rb +9 -0
  48. data/app/concepts/form/js/form.js +136 -0
  49. data/app/concepts/form/view/form.haml +2 -0
  50. data/app/concepts/form/view/inline.haml +6 -0
  51. data/app/concepts/form/view/input.haml +29 -0
  52. data/app/concepts/form/view/select.haml +72 -0
  53. data/app/concepts/form/view/submit.haml +3 -0
  54. data/app/concepts/header/cell/header.rb +5 -0
  55. data/app/concepts/header/view/header.haml +3 -0
  56. data/app/concepts/heading/cell/heading.rb +5 -0
  57. data/app/concepts/heading/view/heading.haml +50 -0
  58. data/app/concepts/html/cell/html.rb +17 -0
  59. data/app/concepts/html/js/html.js +10 -0
  60. data/app/concepts/html/view/html.haml +3 -0
  61. data/app/concepts/icon/cell/icon.rb +5 -0
  62. data/app/concepts/icon/view/icon.haml +6 -0
  63. data/app/concepts/img/cell/img.rb +5 -0
  64. data/app/concepts/img/view/img.haml +1 -0
  65. data/app/concepts/input/cell/input.rb +5 -0
  66. data/app/concepts/input/view/input.haml +3 -0
  67. data/app/concepts/label/cell/label.rb +5 -0
  68. data/app/concepts/label/view/label.haml +7 -0
  69. data/app/concepts/li/cell/li.rb +5 -0
  70. data/app/concepts/li/view/li.haml +6 -0
  71. data/app/concepts/link/cell/link.rb +24 -0
  72. data/app/concepts/link/view/link.haml +6 -0
  73. data/app/concepts/main/cell/main.rb +5 -0
  74. data/app/concepts/main/view/main.haml +3 -0
  75. data/app/concepts/nav/cell/nav.rb +5 -0
  76. data/app/concepts/nav/view/nav.haml +3 -0
  77. data/app/concepts/ol/cell/ol.rb +5 -0
  78. data/app/concepts/ol/view/ol.haml +3 -0
  79. data/app/concepts/onclick/cell/onclick.rb +6 -0
  80. data/app/concepts/onclick/js/onclick.js +21 -0
  81. data/app/concepts/onclick/view/onclick.haml +2 -0
  82. data/app/concepts/page/cell/content.rb +5 -0
  83. data/app/concepts/page/cell/page.rb +128 -0
  84. data/app/concepts/page/js/content.js +17 -0
  85. data/app/concepts/page/utils/page_node.rb +66 -0
  86. data/app/concepts/page/view/content.haml +7 -0
  87. data/app/concepts/page/view/page.haml +9 -0
  88. data/app/concepts/partial/cell/partial.rb +5 -0
  89. data/app/concepts/partial/view/partial.haml +2 -0
  90. data/app/concepts/pg/cell/pg.rb +5 -0
  91. data/app/concepts/pg/view/pg.haml +8 -0
  92. data/app/concepts/plain/cell/plain.rb +10 -0
  93. data/app/concepts/progress/cell/progress.rb +5 -0
  94. data/app/concepts/progress/view/progress.haml +3 -0
  95. data/app/concepts/section/cell/section.rb +5 -0
  96. data/app/concepts/section/view/section.haml +3 -0
  97. data/app/concepts/shared/utils/to_cell.rb +126 -0
  98. data/app/concepts/slot/cell/slot.rb +10 -0
  99. data/app/concepts/slot/view/slot.haml +2 -0
  100. data/app/concepts/span/cell/span.rb +5 -0
  101. data/app/concepts/span/view/span.haml +3 -0
  102. data/app/concepts/table/cell/table.rb +5 -0
  103. data/app/concepts/table/view/table.haml +3 -0
  104. data/app/concepts/td/cell/td.rb +5 -0
  105. data/app/concepts/td/view/td.haml +8 -0
  106. data/app/concepts/th/cell/th.rb +5 -0
  107. data/app/concepts/th/view/th.haml +8 -0
  108. data/app/concepts/tr/cell/tr.rb +5 -0
  109. data/app/concepts/tr/view/tr.haml +3 -0
  110. data/app/concepts/transition/cell/transition.rb +31 -0
  111. data/app/concepts/transition/js/transition.js +26 -0
  112. data/app/concepts/transition/view/transition.haml +7 -0
  113. data/app/concepts/ul/cell/ul.rb +5 -0
  114. data/app/concepts/ul/view/ul.haml +3 -0
  115. data/app/concepts/view/cell/view.rb +7 -0
  116. data/app/concepts/view/js/view.js +42 -0
  117. data/app/concepts/view/view/view.haml +2 -0
  118. data/app/controllers/basemate/ui/core/application_controller.rb +9 -0
  119. data/app/controllers/basemate/ui/core/docs_controller.rb +17 -0
  120. data/app/helpers/matestack/ui/core/application_helper.rb +35 -0
  121. data/config/routes.rb +3 -0
  122. data/lib/matestack/ui/core.rb +15 -0
  123. data/lib/matestack/ui/core/engine.rb +19 -0
  124. data/lib/matestack/ui/core/version.rb +7 -0
  125. data/lib/tasks/matestack/ui/core_tasks.rake +4 -0
  126. data/vendor/assets/javascripts/manifest.json +4 -0
  127. data/vendor/assets/javascripts/matestack-ui-core.js +15055 -0
  128. data/vendor/assets/javascripts/matestack-ui-core.js.map +1 -0
  129. metadata +277 -0
@@ -0,0 +1,3 @@
1
+ %a{"@click.prevent": "perform", "href": action_path}
2
+ - if block_given?
3
+ = yield
@@ -0,0 +1,76 @@
1
+ module App::Cell
2
+ class App < Trailblazer::Cell
3
+ include ActionView::Helpers::ActiveModelHelper
4
+ include ActionView::Helpers::ActiveModelInstanceTag
5
+ include ActionView::Helpers::AssetTagHelper
6
+ include ActionView::Helpers::AssetUrlHelper
7
+ include ActionView::Helpers::AtomFeedHelper
8
+ include ActionView::Helpers::CacheHelper
9
+ include ActionView::Helpers::CaptureHelper
10
+ include ActionView::Helpers::CspHelper
11
+ include ActionView::Helpers::CsrfHelper
12
+ include ActionView::Helpers::DateHelper
13
+ include ActionView::Helpers::DebugHelper
14
+ include ActionView::Helpers::FormHelper
15
+ include ActionView::Helpers::FormOptionsHelper
16
+ include ActionView::Helpers::FormTagHelper
17
+ include ActionView::Helpers::JavaScriptHelper
18
+ include ActionView::Helpers::NumberHelper
19
+ include ActionView::Helpers::OutputSafetyHelper
20
+ include ActionView::Helpers::RecordTagHelper
21
+ # include ActionView::Helpers::RenderingHelper
22
+ include ActionView::Helpers::SanitizeHelper
23
+ include ActionView::Helpers::TagHelper
24
+ include ActionView::Helpers::TextHelper
25
+ include ActionView::Helpers::TranslationHelper
26
+ include ActionView::Helpers::UrlHelper
27
+ include ::Cell::Haml
28
+ include ::Matestack::Ui::Core::ApplicationHelper
29
+ include Shared::Utils::ToCell
30
+ # include ::Rails.application.routes.url_helpers
31
+
32
+ view_paths << "#{Matestack::Ui::Core::Engine.root}/app/concepts"
33
+
34
+ def initialize(model=nil, options={})
35
+ super
36
+ @nodes = {}
37
+ @cells = {}
38
+ @page_block = nil
39
+ @page_id = ""
40
+ setup
41
+ end
42
+
43
+ def setup
44
+ true
45
+ end
46
+
47
+ def prepare
48
+ true
49
+ end
50
+
51
+ def show(page_id, page_nodes, &block)
52
+ @page_id = page_id
53
+ @page_nodes = page_nodes
54
+ prepare
55
+ response
56
+ render(view: :app, &block)
57
+ end
58
+
59
+ def page_nodes
60
+ @page_nodes
61
+ end
62
+
63
+ def components(&block)
64
+ @nodes = ::App::Utils::AppNode.build(self, &block)
65
+
66
+ @nodes.each do |key, node|
67
+ @cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"], nil)
68
+ end
69
+ end
70
+
71
+ def partial(&block)
72
+ ::App::Utils::AppNode.build(self, &block)
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,27 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+ import axios from 'axios'
3
+ import VRuntimeTemplate from "v-runtime-template"
4
+ import Vuex from 'vuex'
5
+
6
+ const componentDef = {
7
+ props: ['appConfig', 'params'],
8
+ data: function(){
9
+ return {}
10
+ },
11
+ computed: Vuex.mapState({
12
+ asyncTemplate: state => state.pageTemplate,
13
+ }),
14
+ mounted: function(){
15
+ const self = this;
16
+ window.onpopstate = function(event) {
17
+ self.$store.dispatch("navigateTo", {url: document.location.pathname, backwards: true} );
18
+ }
19
+ },
20
+ components: {
21
+ VRuntimeTemplate: VRuntimeTemplate
22
+ }
23
+ }
24
+
25
+ let component = Vue.component('app-cell', componentDef)
26
+
27
+ export default componentDef
@@ -0,0 +1,71 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+ import Vuex from 'vuex'
3
+ import axios from 'axios'
4
+
5
+ import matestackEventHub from 'core/js/event-hub'
6
+
7
+ Vue.use(Vuex)
8
+
9
+ const store = new Vuex.Store({
10
+ state: {
11
+ pageTemplate: null,
12
+ currentPath: document.location.pathname
13
+ },
14
+ mutations: {
15
+ setPageTemplate (state, serverResponse){
16
+ state.pageTemplate = serverResponse
17
+ },
18
+ setCurrentPath (state, path){
19
+ state.currentPath = path
20
+ }
21
+ },
22
+ actions: {
23
+ navigateTo ({ commit, state }, { url, backwards }) {
24
+ matestackEventHub.$emit("page_loading", url);
25
+ if (typeof matestackUiCoreTransitionStart !== 'undefined') {
26
+ matestackUiCoreTransitionStart(url);
27
+ }
28
+ if (!window.history.pushState) {
29
+ document.location.href = url;
30
+ return;
31
+ }
32
+ return new Promise((resolve, reject) => {
33
+ axios({
34
+ method: "get",
35
+ url: url,
36
+ headers: {
37
+ 'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
38
+ },
39
+ params: {"only_page": true}
40
+ })
41
+ .then(function(response){
42
+ if (backwards){
43
+ window.history.replaceState({matestackApp: true, url: url}, null, url);
44
+ } else {
45
+ window.history.pushState({matestackApp: true, url: url}, null, url);
46
+ }
47
+ setTimeout(function () {
48
+ resolve(response["data"])
49
+ commit('setPageTemplate', response["data"])
50
+ commit('setCurrentPath', url)
51
+ matestackEventHub.$emit("page_loaded", url);
52
+ if (typeof matestackUiCoreTransitionSuccess !== 'undefined') {
53
+ matestackUiCoreTransitionSuccess(url);
54
+ }
55
+ }, 5);
56
+ })
57
+ .catch(function(error){
58
+ setTimeout(function () {
59
+ resolve(error)
60
+ matestackEventHub.$emit("page_loading_error", error);
61
+ if (typeof matestackUiCoreTransitionError !== 'undefined') {
62
+ matestackUiCoreTransitionError(url);
63
+ }
64
+ }, 5);
65
+ })
66
+ })
67
+ }
68
+ }
69
+ })
70
+
71
+ export default store
@@ -0,0 +1,53 @@
1
+ module App::Utils
2
+ class AppNode
3
+
4
+ def self.build(app_instance, &block)
5
+ node = AppNode.new(app_instance)
6
+ node.instance_eval(&block)
7
+ node.hash
8
+ end
9
+
10
+ attr_reader :hash
11
+
12
+ def initialize(app_instance)
13
+ @hash = {}
14
+ @node_start_id = 0
15
+ @app_instance = app_instance
16
+ app_instance.instance_variables.each do |app_instance_var_key|
17
+ self.instance_variable_set(app_instance_var_key, app_instance.instance_variable_get(app_instance_var_key))
18
+ end
19
+ end
20
+
21
+ def method_missing meth, *args, &block
22
+ begin
23
+ @app_instance.send(meth, *args, &block)
24
+ rescue
25
+ node_id = @node_start_id + 1
26
+ @node_start_id = node_id
27
+ current_node = "#{meth}_#{@node_start_id}"
28
+ @hash[current_node] = {}
29
+ @hash[current_node]["component_name"] = meth.to_s
30
+ @hash[current_node]["config"] = {}
31
+ @hash[current_node]["argument"] = nil
32
+
33
+ if meth == :page_content
34
+ @hash[current_node]["components"] = @app_instance.send(:page_nodes)
35
+ elsif meth == :partial
36
+ @hash[current_node]["components"] = @app_instance.send(args.first, *args.drop(1))
37
+ else
38
+ if args.first.is_a?(Hash)
39
+ @hash[current_node]["config"] = args.first
40
+ else
41
+ @hash[current_node]["argument"] = args.first
42
+ end
43
+
44
+ if block_given?
45
+ @hash[current_node]["components"] = AppNode.build(@app_instance, &block)
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ %component{"is": "app-cell", "inline-template": true}
2
+ %div{"class": "matestack_app"}
3
+ - @cells.each do |key, cell|
4
+ = cell.call(:show)
@@ -0,0 +1,10 @@
1
+ module Async::Cell
2
+ class Async < Component::Cell::Dynamic
3
+
4
+ def setup
5
+ @rerender = true
6
+ end
7
+
8
+
9
+ end
10
+ end
@@ -0,0 +1,57 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+
3
+ import matestackEventHub from 'core/js/event-hub'
4
+
5
+ import componentMixin from 'component/js/component'
6
+
7
+ const componentDef = {
8
+ mixins: [componentMixin],
9
+ data: function(){
10
+ return {
11
+ showing: true,
12
+ hide_after_timeout: null,
13
+ event: {
14
+ data: {}
15
+ }
16
+ }
17
+ },
18
+ methods: {
19
+ show: function(event_data){
20
+ const self = this
21
+ this.showing = true
22
+ this.event.data = event_data
23
+ if(this.componentConfig["hide_after"] != undefined){
24
+ self.hide_after_timeout = setTimeout(function () {
25
+ self.hide()
26
+ }, parseInt(this.componentConfig["hide_after"]));
27
+ }
28
+ },
29
+ hide: function(){
30
+ this.showing = false
31
+ this.event.data = {}
32
+ }
33
+ },
34
+ created: function () {
35
+ const self = this
36
+ matestackEventHub.$on(this.componentConfig["rerender_on"], self.rerender)
37
+ matestackEventHub.$on(this.componentConfig["show_on"], self.show)
38
+ matestackEventHub.$on(this.componentConfig["hide_on"], self.hide)
39
+ if(this.componentConfig["show_on"] != undefined){
40
+ this.showing = false
41
+ }
42
+ if(this.componentConfig["hide_on"] != undefined){
43
+ this.showing = true
44
+ }
45
+ },
46
+ beforeDestroy: function() {
47
+ const self = this
48
+ clearTimeout(self.hide_after_timeout)
49
+ matestackEventHub.$off(this.componentConfig["rerender_on"], self.rerender);
50
+ matestackEventHub.$off(this.componentConfig["show_on"], self.show);
51
+ matestackEventHub.$off(this.componentConfig["hide_on"], self.hide);
52
+ },
53
+ }
54
+
55
+ let component = Vue.component('async-cell', componentDef)
56
+
57
+ export default componentDef
@@ -0,0 +1,2 @@
1
+ %div{"v-if": "showing"}
2
+ = yield
@@ -0,0 +1,5 @@
1
+ module Br::Cell
2
+ class Br < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ - unless options[:times].nil?
2
+ - options[:times].times do
3
+ %br
4
+ - else
5
+ %br
@@ -0,0 +1,5 @@
1
+ module Button::Cell
2
+ class Button < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ - if options[:text].nil?
2
+ %button{@tag_attributes}
3
+ - if block_given?
4
+ = yield
5
+ - else
6
+ %button{@tag_attributes}
7
+ = options[:text]
@@ -0,0 +1,226 @@
1
+ module Component::Cell
2
+ class Dynamic < Trailblazer::Cell
3
+ include ActionView::Helpers::ActiveModelHelper
4
+ include ActionView::Helpers::ActiveModelInstanceTag
5
+ include ActionView::Helpers::AssetTagHelper
6
+ include ActionView::Helpers::AssetUrlHelper
7
+ include ActionView::Helpers::AtomFeedHelper
8
+ include ActionView::Helpers::CacheHelper
9
+ include ActionView::Helpers::CaptureHelper
10
+ include ActionView::Helpers::CspHelper
11
+ include ActionView::Helpers::CsrfHelper
12
+ include ActionView::Helpers::DateHelper
13
+ include ActionView::Helpers::DebugHelper
14
+ include ActionView::Helpers::FormHelper
15
+ include ActionView::Helpers::FormOptionsHelper
16
+ include ActionView::Helpers::FormTagHelper
17
+ include ActionView::Helpers::JavaScriptHelper
18
+ include ActionView::Helpers::NumberHelper
19
+ include ActionView::Helpers::OutputSafetyHelper
20
+ include ActionView::Helpers::RecordTagHelper
21
+ # include ActionView::Helpers::RenderingHelper
22
+ include ActionView::Helpers::SanitizeHelper
23
+ include ActionView::Helpers::TagHelper
24
+ include ActionView::Helpers::TextHelper
25
+ include ActionView::Helpers::TranslationHelper
26
+ include ActionView::Helpers::UrlHelper
27
+ # include ActionView::Helpers::UrlHelper
28
+ # include ActionView::Helpers::TranslationHelper
29
+ include ::Cell::Haml
30
+ include ::Matestack::Ui::Core::ApplicationHelper
31
+ include Shared::Utils::ToCell
32
+
33
+ view_paths << "#{Matestack::Ui::Core::Engine.root}/app/concepts"
34
+ view_paths << "#{::Rails.root}/app/matestack"
35
+
36
+ def initialize(model=nil, options={})
37
+ super
38
+ @component_config = options.except(:context, :children, :url_params, :included_config)
39
+ @url_params = options[:url_params].except(:action, :controller, :component_key)
40
+ @component_key = options[:component_key]
41
+ @children_cells = {}
42
+ @controller_context = context[:controller_context]
43
+ @argument = model
44
+ @static = false
45
+ @nodes = {}
46
+ @cells = {}
47
+ @included_config = options[:included_config]
48
+ @rerender = false
49
+ @options = options
50
+ generate_component_name
51
+ generate_children_cells
52
+ set_tag_attributes
53
+ validate_options
54
+ setup
55
+ end
56
+
57
+ def validate_options
58
+ if defined? self.class::REQUIRED_KEYS
59
+ self.class::REQUIRED_KEYS.each do |key|
60
+ raise "required key '#{key}' is missing" if options[key].nil?
61
+ end
62
+ end
63
+ custom_options_validation
64
+ end
65
+
66
+ def custom_options_validation
67
+ true
68
+ end
69
+
70
+ def setup
71
+ true
72
+ end
73
+
74
+ def show(&block)
75
+ if respond_to? :prepare
76
+ prepare
77
+ end
78
+ if respond_to? :response
79
+ response &block
80
+ if @static
81
+ render :response
82
+ else
83
+ if @rerender
84
+ render :response_dynamic
85
+ else
86
+ render :response_dynamic_without_rerender
87
+ end
88
+ end
89
+ else
90
+ if @static
91
+ render(view: :static, &block)
92
+ else
93
+ if @rerender
94
+ render(view: :dynamic, &block)
95
+ else
96
+ render(view: :dynamic_without_rerender, &block)
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ def render_children
103
+ render(view: :children)
104
+ end
105
+
106
+ def render_content(&block)
107
+ if respond_to? :prepare
108
+ prepare
109
+ end
110
+ if respond_to? :response
111
+ response &block
112
+ render :response
113
+ else
114
+ render do
115
+ render_children
116
+ end
117
+ end
118
+ end
119
+
120
+ def component_id
121
+ options[:id] ||= nil
122
+ end
123
+
124
+ def js_action name, arguments
125
+ argumentString = arguments.join('", "')
126
+ argumentString = '"' + argumentString + '"'
127
+ [name, '(', argumentString, ')'].join("")
128
+ end
129
+
130
+ def navigate_to path
131
+ js_action("navigateTo", [path])
132
+ end
133
+
134
+ def components(&block)
135
+ @nodes = ::Component::Utils::ComponentNode.build(self, nil, &block)
136
+
137
+ @nodes.each do |key, node|
138
+ @cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"], node["included_config"])
139
+ end
140
+ end
141
+
142
+ def partial(&block)
143
+ return ::Component::Utils::ComponentNode.build(self, nil, &block)
144
+ end
145
+
146
+ def slot(&block)
147
+ return ::Component::Utils::ComponentNode.build(self, nil, &block)
148
+ end
149
+
150
+ def get_children
151
+ return options[:children]
152
+ end
153
+
154
+ def to_css_class(symbol)
155
+ symbol.to_s.gsub("_", "-")
156
+ end
157
+
158
+ def modifiers
159
+ result = []
160
+ return unless defined? self.class::OPTIONS
161
+ self.class::OPTIONS.select{ |modifer_key, modifier_options|
162
+ modifier_options[:css_modifier] == true
163
+ }.each do |modifer_key, modifier_options|
164
+ if !options[modifer_key] == false || modifier_options[:default] == true
165
+ result << "#{to_css_class(self.class::CSSClASS)}--#{to_css_class(modifer_key)}"
166
+ end
167
+ end
168
+ result.join(" ")
169
+ end
170
+
171
+
172
+ private
173
+
174
+ def generate_children_cells
175
+ unless options[:children].nil?
176
+ #needs refactoring --> in some cases, :component_key, :children, :origin_url, :url_params, :included_config get passed into options[:children] which causes errors
177
+ #quickfix: except them from iteration
178
+ options[:children].except(:component_key, :children, :origin_url, :url_params, :included_config).each do |key, node|
179
+ @children_cells[key] = to_cell("#{@component_key}__#{key}", node["component_name"], node["config"], node["argument"], node["components"], node["included_config"])
180
+ end
181
+ end
182
+ end
183
+
184
+ def generate_component_name
185
+ name_parts = self.class.name.split("::")
186
+ module_name = name_parts[0]
187
+ if module_name == "Components"
188
+ name_parts.shift
189
+ end
190
+ name = name_parts[0] + name_parts[1]
191
+ if name_parts[0] == name_parts[2]
192
+ name = name_parts[0] + name_parts[1]
193
+ @component_class = name.underscore.gsub("_", "-")
194
+ else
195
+ name = name_parts[0] + name_parts[2] + name_parts[1]
196
+ @component_class = name.underscore.gsub("_", "-")
197
+ end
198
+ @component_name = @component_class.gsub("-cell", "")
199
+ end
200
+
201
+ def set_tag_attributes
202
+ default_attributes = {
203
+ "id": component_id,
204
+ "class": options[:class]
205
+ }
206
+ unless options[:attributes].nil?
207
+ default_attributes.merge!(options[:attributes])
208
+ end
209
+
210
+ @tag_attributes = default_attributes
211
+ end
212
+
213
+ def dynamic_tag_attributes
214
+ attrs = {
215
+ "is": @component_class,
216
+ "ref": component_id,
217
+ ":params": @url_params.to_json,
218
+ ":component-config": @component_config.to_json,
219
+ "inline-template": true,
220
+ }
221
+ attrs.merge!(options[:attributes]) unless options[:attributes].nil?
222
+ return attrs
223
+ end
224
+
225
+ end
226
+ end