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,16 @@
1
+ module Component::Cell
2
+ class Static < Component::Cell::Dynamic
3
+
4
+ def initialize(model=nil, options={})
5
+ super
6
+ if options[:dynamic]
7
+ @static = false
8
+ @rerender = true
9
+ @component_class = "anonym-dynamic-component-cell"
10
+ else
11
+ @static = true
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+ import componentMixin from 'component/js/component'
3
+
4
+ const componentDef = {
5
+ mixins: [componentMixin]
6
+ }
7
+
8
+ let component = Vue.component('anonym-dynamic-component-cell', componentDef)
9
+
10
+ export default componentDef
@@ -0,0 +1,60 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+ import axios from 'axios'
3
+ import VRuntimeTemplate from "v-runtime-template"
4
+
5
+ import matestackEventHub from 'core/js/event-hub'
6
+
7
+ const componentMixin = {
8
+ props: ['componentConfig', 'params'],
9
+ data: function(){
10
+ return {
11
+ asyncTemplate: null
12
+ }
13
+ },
14
+ methods: {
15
+ onRerender: function(event){
16
+ if (this.$el.id === event+"__wrapper"){
17
+ this.rerender()
18
+ }
19
+ },
20
+ onMatestackUiCoreChannel: function(event){
21
+ if (this.componentConfig["rerender_on"] == event.message){
22
+ this.rerender()
23
+ }
24
+ },
25
+ rerender: function(){
26
+ var self = this;
27
+ self.params["component_key"] = self.componentConfig["component_key"]
28
+ axios({
29
+ method: "get",
30
+ url: self.componentConfig["origin_url"],
31
+ headers: {
32
+ 'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
33
+ },
34
+ params: self.params
35
+ })
36
+ .then(function(response){
37
+ self.asyncTemplate = response["data"];
38
+ })
39
+ },
40
+ rerenderWith: function(newParams){
41
+ Object.assign(this.params, newParams);
42
+ this.rerender()
43
+ }
44
+ },
45
+ created: function () {
46
+ const self = this
47
+ matestackEventHub.$on('rerender', self.onRerender)
48
+ matestackEventHub.$on('MatestackUiCoreChannel', self.onMatestackUiCoreChannel)
49
+ },
50
+ beforeDestroy: function() {
51
+ const self = this
52
+ matestackEventHub.$off('rerender', self.onRerender);
53
+ matestackEventHub.$off('MatestackUiCoreChannel', self.onMatestackUiCoreChannel)
54
+ },
55
+ components: {
56
+ VRuntimeTemplate: VRuntimeTemplate
57
+ }
58
+ }
59
+
60
+ export default componentMixin
@@ -0,0 +1,69 @@
1
+ module Component::Utils
2
+ class ComponentNode
3
+
4
+ def self.build(component_instance, included_config, &block)
5
+ node = ComponentNode.new(component_instance, included_config)
6
+ node.instance_eval(&block)
7
+ node.hash
8
+ end
9
+
10
+ attr_reader :hash
11
+
12
+ def initialize(component_instance, included_config)
13
+ @hash = {}
14
+ @node_start_id = 0
15
+ @component_instance = component_instance
16
+ @included_config = included_config
17
+ component_instance.instance_variables.each do |component_instance_var_key|
18
+ self.instance_variable_set(component_instance_var_key, component_instance.instance_variable_get(component_instance_var_key))
19
+ end
20
+ end
21
+
22
+ def method_missing meth, *args, &block
23
+ begin
24
+ @component_instance.send(meth, *args, &block)
25
+ rescue
26
+ node_id = @node_start_id + 1
27
+ @node_start_id = node_id
28
+ current_node = "#{meth}_#{@node_start_id}"
29
+ @hash[current_node] = {}
30
+ @hash[current_node]["component_name"] = meth.to_s
31
+ @hash[current_node]["config"] = {}
32
+ @hash[current_node]["argument"] = nil
33
+ @hash[current_node]["included_config"] = @included_config
34
+
35
+ if meth == :partial
36
+ @hash[current_node]["components"] = @component_instance.send(args.first, *args.drop(1))
37
+ elsif meth == :yield_components
38
+ @hash[current_node]["component_name"] = "partial"
39
+ @hash[current_node]["components"] = @component_instance.send(:get_children)
40
+ else
41
+ if args.first.is_a?(Hash)
42
+ @hash[current_node]["config"] = args.first
43
+ else
44
+ @hash[current_node]["argument"] = args.first
45
+ end
46
+
47
+ if args.second == :include
48
+ included = args.first
49
+ else
50
+ unless @included_config.nil?
51
+ included = @included_config
52
+ else
53
+ included = nil
54
+ end
55
+ end
56
+
57
+ if block_given?
58
+ @hash[current_node]["components"] = ComponentNode.build(@component_instance, included, &block)
59
+ elsif meth == :slot
60
+ # @hash[current_node]["components"] = ComponentNode.build(@component_instance, included, &args.first)
61
+ @hash[current_node]["components"] = args.first
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,2 @@
1
+ - @children_cells.each do |key, cell|
2
+ = cell.call(:show)
@@ -0,0 +1,6 @@
1
+ %component{dynamic_tag_attributes}
2
+ %div
3
+ %div{"v-if": "asyncTemplate == null"}
4
+ = render_content
5
+ %div{"v-if": "asyncTemplate != null"}
6
+ %v-runtime-template{":template":"asyncTemplate"}
@@ -0,0 +1,2 @@
1
+ %component{dynamic_tag_attributes}
2
+ = render_content
@@ -0,0 +1,2 @@
1
+ - @cells.each do |key, cell|
2
+ = cell.call(:show)
@@ -0,0 +1,7 @@
1
+ %component{dynamic_tag_attributes}
2
+ %div{"id": component_id, "class": @component_class}
3
+ %div{"v-if": "asyncTemplate == null"}
4
+ - @cells.each do |key, cell|
5
+ = cell.call(:show)
6
+ %div{"v-if": "asyncTemplate != null"}
7
+ %v-runtime-template{":template":"asyncTemplate"}
@@ -0,0 +1,3 @@
1
+ %component{dynamic_tag_attributes}
2
+ - @cells.each do |key, cell|
3
+ = cell.call(:show)
@@ -0,0 +1 @@
1
+ = render_content
@@ -0,0 +1,27 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+
3
+ import app from 'app/js/app'
4
+ import async from 'async/js/async'
5
+ import pageContent from 'page/js/content'
6
+ import store from 'app/js/store'
7
+ import component from 'component/js/component'
8
+ import anonymDynamicComponent from 'component/js/anonym-dynamic-component'
9
+ import html from 'html/js/html'
10
+ import transition from 'transition/js/transition'
11
+ import action from 'action/js/action'
12
+ import form from 'form/js/form'
13
+ import view from 'view/js/view'
14
+ import onclick from 'onclick/js/onclick'
15
+
16
+ let matestackUiApp = undefined
17
+
18
+ document.addEventListener('DOMContentLoaded', () => {
19
+
20
+ matestackUiApp = new Vue({
21
+ el: "#matestack_ui",
22
+ store: store
23
+ })
24
+
25
+ })
26
+
27
+ export default Vue
@@ -0,0 +1,5 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+
3
+ const matestackEventHub = new Vue();
4
+
5
+ export default matestackEventHub
@@ -0,0 +1,6 @@
1
+ module Div::Cell
2
+ class Div < Component::Cell::Static
3
+
4
+
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ %div{@tag_attributes}
2
+ - if block_given?
3
+ = yield
@@ -0,0 +1,5 @@
1
+ module Footer::Cell
2
+ class Footer < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %footer{@tag_attributes}
2
+ - if block_given?
3
+ = yield
@@ -0,0 +1,71 @@
1
+ module Form::Cell
2
+ class Form < Component::Cell::Dynamic
3
+
4
+ REQUIRED_KEYS = [:for, :path, :method]
5
+
6
+ def setup
7
+ begin
8
+ @component_config[:for] = form_wrapper
9
+ @component_config[:submit_path] = submit_path
10
+ @component_config[:method] = options[:method]
11
+ @component_config[:success] = options[:success]
12
+ unless options[:success].nil?
13
+ unless options[:success][:transition].nil?
14
+ @component_config[:success][:transition][:path] = transition_path options[:success]
15
+ end
16
+ end
17
+ @component_config[:failure] = options[:failure]
18
+ unless options[:failure].nil?
19
+ unless options[:failure][:transition].nil?
20
+ @component_config[:failure][:transition][:path] = transition_path options[:failure]
21
+ end
22
+ end
23
+ @tag_attributes.merge!({"@submit.prevent": true})
24
+ rescue => e
25
+ raise "Form component could not be setted up. Reason: #{e}"
26
+ end
27
+ end
28
+
29
+ def submit_path
30
+ begin
31
+ if options[:path].is_a?(Symbol)
32
+ return ::Rails.application.routes.url_helpers.send(options[:path], options[:params])
33
+ else
34
+ return options[:path]
35
+ end
36
+ rescue
37
+ raise "Submit path not found"
38
+ end
39
+ end
40
+
41
+ def transition_path callback_options
42
+ begin
43
+ if callback_options[:transition][:path].is_a?(Symbol)
44
+ return ::Rails.application.routes.url_helpers.send(
45
+ callback_options[:transition][:path],
46
+ callback_options[:transition][:params]
47
+ )
48
+ else
49
+ return callback_options[:transition][:path]
50
+ end
51
+ rescue
52
+ raise "Transition path not found"
53
+ end
54
+ end
55
+
56
+ def form_wrapper
57
+ case options[:for]
58
+ when Symbol
59
+ return options[:for]
60
+ when String
61
+ return options[:for]
62
+ end
63
+
64
+ if options[:for].respond_to?(:model_name)
65
+ return options[:for].model_name.singular
66
+ end
67
+ end
68
+
69
+
70
+ end
71
+ end
@@ -0,0 +1,9 @@
1
+ module Form::Cell
2
+ class Inline < Component::Cell::Static
3
+
4
+ def input_key
5
+ 'data["' + options[:key].to_s + '"]'
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,74 @@
1
+ module Form::Cell
2
+ class Input < Component::Cell::Static
3
+
4
+ REQUIRED_KEYS = [:key, :type]
5
+
6
+ def custom_options_validation
7
+ raise "included form config is missing, please add ':include' to parent form component" if @included_config.nil?
8
+ end
9
+
10
+ def input_key
11
+ 'data["' + options[:key].to_s + '"]'
12
+ end
13
+
14
+ def error_key
15
+ 'errors["' + options[:key].to_s + '"]'
16
+ end
17
+
18
+ def input_wrapper
19
+ case options[:for]
20
+ when nil
21
+ return nil
22
+ when Symbol
23
+ return options[:for]
24
+ when String
25
+ return options[:for]
26
+ end
27
+ if options[:for].respond_to?(:model_name)
28
+ return options[:for].model_name.singular
29
+ end
30
+ end
31
+
32
+ def attr_key
33
+ if input_wrapper.nil?
34
+ return options[:key].to_s
35
+ else
36
+ return "#{input_wrapper}.#{options[:key].to_s}"
37
+ end
38
+ end
39
+
40
+ def init_value
41
+ unless options[:init].nil?
42
+ return options[:init]
43
+ end
44
+
45
+ unless options[:for].nil?
46
+ value = options[:for].send(options[:key])
47
+ if [true, false].include? value
48
+ value ? 1 : 0
49
+ else
50
+ return value
51
+ end
52
+ else
53
+ unless @included_config.nil? && @included_config[:for].nil?
54
+ if @included_config[:for].respond_to?(options[:key])
55
+ value = @included_config[:for].send(options[:key])
56
+ if [true, false].include? value
57
+ value ? 1 : 0
58
+ else
59
+ return value
60
+ end
61
+ else
62
+ if @included_config[:for].is_a?(Symbol) || @included_config[:for].is_a?(String)
63
+ return nil
64
+ end
65
+ if @included_config[:for].is_a?(Hash)
66
+ return @included_config[:for][options[:key]]
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,73 @@
1
+ module Form::Cell
2
+ class Select < Component::Cell::Static
3
+
4
+ REQUIRED_KEYS = [:options]
5
+
6
+ def input_key
7
+ 'data["' + options[:key].to_s + '"]'
8
+ end
9
+
10
+ def error_key
11
+ 'errors["' + options[:key].to_s + '"]'
12
+ end
13
+
14
+ def attr_key
15
+ options[:key].to_s
16
+ end
17
+
18
+ def option_values
19
+ values = options[:options] if options[:options].is_a?(Array)
20
+ values = options[:options].keys if options[:options].is_a?(Hash)
21
+ return values
22
+ end
23
+
24
+ def options_type
25
+ return Integer if option_values.first.is_a?(Integer)
26
+ return String if option_values.first.is_a?(String)
27
+ end
28
+
29
+ def model_binding
30
+
31
+ if option_values.first.is_a?(Integer)
32
+ return "v-model.number"
33
+ else
34
+ return "v-model"
35
+ end
36
+ end
37
+
38
+ def init_value
39
+ unless options[:init].nil?
40
+ return options[:init]
41
+ end
42
+
43
+ unless options[:for].nil?
44
+ value = options[:for].send(options[:key])
45
+ if [true, false].include? value
46
+ value ? 1 : 0
47
+ else
48
+ return value
49
+ end
50
+ else
51
+ unless @included_config.nil? && @included_config[:for].nil?
52
+ if @included_config[:for].respond_to?(options[:key])
53
+ value = @included_config[:for].send(options[:key])
54
+ if [true, false].include? value
55
+ value ? 1 : 0
56
+ else
57
+ return value
58
+ end
59
+ else
60
+ if @included_config[:for].is_a?(Symbol) || @included_config[:for].is_a?(String)
61
+ return nil
62
+ end
63
+ if @included_config[:for].is_a?(Hash)
64
+ return @included_config[:for][options[:key]]
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+
72
+ end
73
+ end