basemate-ui-core 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +495 -0
  4. data/Rakefile +32 -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/app/cell/app.rb +75 -0
  9. data/app/concepts/app/js/app.js +27 -0
  10. data/app/concepts/app/js/store.js +66 -0
  11. data/app/concepts/app/utils/app_node.rb +53 -0
  12. data/app/concepts/app/view/app.haml +4 -0
  13. data/app/concepts/component/cell/dynamic.rb +110 -0
  14. data/app/concepts/component/cell/static.rb +14 -0
  15. data/app/concepts/component/js/component.js +38 -0
  16. data/app/concepts/component/view/children.haml +2 -0
  17. data/app/concepts/component/view/dynamic.haml +6 -0
  18. data/app/concepts/component/view/static.haml +1 -0
  19. data/app/concepts/core/js/core.js +20 -0
  20. data/app/concepts/div/cell/div.rb +5 -0
  21. data/app/concepts/div/view/div.haml +3 -0
  22. data/app/concepts/header/cell/header.rb +5 -0
  23. data/app/concepts/header/view/header.haml +3 -0
  24. data/app/concepts/heading/cell/heading.rb +5 -0
  25. data/app/concepts/heading/view/heading.haml +50 -0
  26. data/app/concepts/html/cell/html.rb +17 -0
  27. data/app/concepts/html/js/html.js +10 -0
  28. data/app/concepts/html/view/html.haml +3 -0
  29. data/app/concepts/img/cell/img.rb +5 -0
  30. data/app/concepts/img/view/img.haml +1 -0
  31. data/app/concepts/link/cell/link.rb +14 -0
  32. data/app/concepts/link/view/link.haml +6 -0
  33. data/app/concepts/main/cell/main.rb +5 -0
  34. data/app/concepts/main/view/main.haml +3 -0
  35. data/app/concepts/nav/cell/nav.rb +5 -0
  36. data/app/concepts/nav/view/nav.haml +3 -0
  37. data/app/concepts/navigation/cell/button.rb +5 -0
  38. data/app/concepts/navigation/view/button.haml +3 -0
  39. data/app/concepts/page/cell/content.rb +5 -0
  40. data/app/concepts/page/cell/page.rb +110 -0
  41. data/app/concepts/page/utils/page_node.rb +51 -0
  42. data/app/concepts/page/view/content.haml +7 -0
  43. data/app/concepts/page/view/page.haml +3 -0
  44. data/app/concepts/partial/cell/partial.rb +5 -0
  45. data/app/concepts/partial/view/partial.haml +3 -0
  46. data/app/concepts/plain/cell/plain.rb +10 -0
  47. data/app/concepts/section/cell/section.rb +5 -0
  48. data/app/concepts/section/view/section.haml +3 -0
  49. data/app/concepts/shared/utils/to_cell.rb +27 -0
  50. data/app/concepts/span/cell/span.rb +5 -0
  51. data/app/concepts/span/view/span.haml +3 -0
  52. data/app/concepts/transition/cell/transition.rb +18 -0
  53. data/app/concepts/transition/js/transition.js +26 -0
  54. data/app/concepts/transition/view/transition.haml +6 -0
  55. data/app/controllers/basemate/ui/core/application_controller.rb +9 -0
  56. data/app/helpers/basemate/ui/core/application_helper.rb +35 -0
  57. data/config/routes.rb +2 -0
  58. data/lib/basemate/ui/core.rb +14 -0
  59. data/lib/basemate/ui/core/engine.rb +19 -0
  60. data/lib/basemate/ui/core/version.rb +7 -0
  61. data/lib/tasks/basemate/ui/core_tasks.rake +4 -0
  62. metadata +190 -0
@@ -0,0 +1,2 @@
1
+ - @children_cells.each do |key, cell|
2
+ = cell.call(:show)
@@ -0,0 +1,6 @@
1
+ %component{"is": @component_class, ":params": @url_params.to_json, ":component-config": @component_config.to_json, "inline-template": true}
2
+ %div{"id": component_id, "class": @component_class}
3
+ %div{"v-if": "asyncTemplate == null"}
4
+ = render_content
5
+ %div{"v-if": "asyncTemplate != null"}
6
+ %v-runtime-template{":template":"asyncTemplate"}
@@ -0,0 +1 @@
1
+ = render_content
@@ -0,0 +1,20 @@
1
+ import Vue from 'vue/dist/vue.esm'
2
+
3
+ import app from 'app/js/app'
4
+ import store from 'app/js/store'
5
+ import component from 'component/js/component'
6
+ import html from 'html/js/html'
7
+ import transition from 'transition/js/transition'
8
+
9
+
10
+
11
+ document.addEventListener('DOMContentLoaded', () => {
12
+
13
+ const basemateUiApp = new Vue({
14
+ el: "#basemate_ui",
15
+ store: store
16
+ })
17
+
18
+ })
19
+
20
+ export default Vue
@@ -0,0 +1,5 @@
1
+ module Div::Cell
2
+ class Div < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %div{"class": options[:class], "id": component_id}
2
+ - if block_given?
3
+ = yield
@@ -0,0 +1,5 @@
1
+ module Header::Cell
2
+ class Header < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %header{"class": options[:class], "id": component_id}
2
+ - if block_given?
3
+ = yield
@@ -0,0 +1,5 @@
1
+ module Heading::Cell
2
+ class Heading < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ - case options[:size]
2
+ - when 1
3
+ %h1{"class": options[:class], "id": component_id}
4
+ - if options[:text].blank?
5
+ - if block_given?
6
+ = yield
7
+ - else
8
+ = options[:text]
9
+ - when 2
10
+ %h2{"class": options[:class], "id": component_id}
11
+ - if options[:text].blank?
12
+ - if block_given?
13
+ = yield
14
+ - else
15
+ = options[:text]
16
+ - when 3
17
+ %h3{"class": options[:class], "id": component_id}
18
+ - if options[:text].blank?
19
+ - if block_given?
20
+ = yield
21
+ - else
22
+ = options[:text]
23
+ - when 4
24
+ %h4{"class": options[:class], "id": component_id}
25
+ - if options[:text].blank?
26
+ - if block_given?
27
+ = yield
28
+ - else
29
+ = options[:text]
30
+ - when 5
31
+ %h5{"class": options[:class], "id": component_id}
32
+ - if options[:text].blank?
33
+ - if block_given?
34
+ = yield
35
+ - else
36
+ = options[:text]
37
+ - when 6
38
+ %h6{"class": options[:class], "id": component_id}
39
+ - if options[:text].blank?
40
+ - if block_given?
41
+ = yield
42
+ - else
43
+ = options[:text]
44
+ - else
45
+ %h1{"class": options[:class], "id": component_id}
46
+ - if options[:text].blank?
47
+ - if block_given?
48
+ = yield
49
+ - else
50
+ = options[:text]
@@ -0,0 +1,17 @@
1
+ require_dependency "cell/partial"
2
+
3
+ module Html::Cell
4
+ class Html < Component::Cell::Dynamic
5
+
6
+ include Cell::ViewModel::Partial
7
+
8
+ view_paths << "#{::Rails.root}/app/views"
9
+
10
+ def include_partial(&block)
11
+ render partial: "#{options[:path]}" do
12
+ capture(&block)
13
+ end
14
+ end
15
+
16
+ end
17
+ 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('html-cell', componentDef)
9
+
10
+ export default component
@@ -0,0 +1,3 @@
1
+ %div{"id": custom_id, "data-basemate-id": component_id}
2
+ = include_partial do
3
+ = yield
@@ -0,0 +1,5 @@
1
+ module Img::Cell
2
+ class Img < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ = image_tag(ActionController::Base.helpers.asset_path(options[:path]), height: options[:height], height: options[:width], alt: options[:alt])
@@ -0,0 +1,14 @@
1
+ module Link::Cell
2
+ class Link < Component::Cell::Static
3
+
4
+ def link_path
5
+ if options[:path].is_a?(Symbol)
6
+ return ::Rails.application.routes.url_helpers.send(options[:path], options[:params])
7
+ end
8
+ if options[:path].is_a?(String)
9
+ return options[:path]
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ - if options[:text].nil?
2
+ = link_to link_path, {"class": options[:class], "id": component_id, method: options[:method] ||= :get, "target": options[:target] ||= nil} do
3
+ - if block_given?
4
+ = yield
5
+ - else
6
+ = link_to options[:text], link_path, {"class": options[:class], "id": component_id, method: options[:method] ||= :get, "target": options[:target] ||= nil}
@@ -0,0 +1,5 @@
1
+ module Main::Cell
2
+ class Main < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %main{"class": options[:class], "id": component_id}
2
+ - if block_given?
3
+ = yield
@@ -0,0 +1,5 @@
1
+ module Nav::Cell
2
+ class Nav < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %nav{"class": options[:class], "id": component_id}
2
+ - if block_given?
3
+ = yield
@@ -0,0 +1,5 @@
1
+ module Navigation::Cell
2
+ class Button < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %div{"id": component_id}
2
+ %button{"@click": navigate_to(@argument) }
3
+ =@argument
@@ -0,0 +1,5 @@
1
+ module Page::Cell
2
+ class Content < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,110 @@
1
+ module Page::Cell
2
+ class Page < Trailblazer::Cell
3
+
4
+ include ActionView::Helpers::TranslationHelper
5
+ include ::Cell::Haml
6
+ include ::Basemate::Ui::Core::ApplicationHelper
7
+ include ::Shared::Utils::ToCell
8
+
9
+ view_paths << "#{Basemate::Ui::Core::Engine.root}/app/concepts"
10
+
11
+ def initialize(model=nil, options={})
12
+ super
13
+ generate_page_name
14
+ set_app_class
15
+ @nodes = {}
16
+ @cells = {}
17
+ options[:controller_instance].instance_variables.each do |controller_instance_var_key|
18
+ unless controller_instance_var_key.to_s.start_with?("@_")
19
+ self.instance_variable_set(controller_instance_var_key, options[:controller_instance].instance_variable_get(controller_instance_var_key))
20
+ end
21
+ end
22
+ end
23
+
24
+ def prepare
25
+ true
26
+ end
27
+
28
+ def components(&block)
29
+ @nodes = ::Page::Utils::PageNode.build(self, &block)
30
+
31
+ @nodes.each do |key, node|
32
+ @cells[key] = to_cell(key, node["component_name"], node["config"], node["argument"], node["components"])
33
+ end
34
+ end
35
+
36
+ def partial(&block)
37
+ ::Page::Utils::PageNode.build(self, &block)
38
+ end
39
+
40
+ def show(component_key=nil, only_page=false)
41
+ prepare
42
+ response
43
+
44
+ render_mode = nil
45
+ render_mode = :only_page if only_page == true
46
+ render_mode = :render_page_with_app if !@app_class.nil? && only_page == false
47
+ render_mode = :only_page if @app_class.nil? && only_page == false
48
+ render_mode = :render_component if !component_key.nil?
49
+
50
+ case render_mode
51
+
52
+ when :only_page
53
+ render :page
54
+ when :render_page_with_app
55
+ concept(@app_class).call(:show, @nodes)
56
+ when :render_component
57
+ if component_key.include?("__")
58
+ keys_array = component_key.gsub("__", "__components__").split("__").map {|k| k.to_s}
59
+ node = @nodes.dig(*keys_array)
60
+ cell = to_cell(component_key, node["component_name"], node["config"], node["components"])
61
+ return cell.render_content
62
+ else
63
+ return @cells.dig(component_key).render_content
64
+ end
65
+ end
66
+ end
67
+
68
+
69
+ def page_id
70
+ @custom_page_id ||= @page_id
71
+ end
72
+
73
+ private
74
+
75
+ def generate_page_name
76
+ name_parts = self.class.name.split("::").map { |name| name.underscore }
77
+ @page_id = name_parts.join("_")
78
+ end
79
+
80
+ def set_app_class
81
+ class_name = self.class.name
82
+ name_parts = class_name.split("::")
83
+ if name_parts.count <= 2
84
+ @app_class = nil
85
+ return
86
+ end
87
+
88
+ app_name = "#{name_parts[1]}"
89
+ begin
90
+ app_class = Apps.const_get(app_name)
91
+ if app_class.is_a?(Class)
92
+ @app_class = app_class
93
+ else
94
+ require_dependency "apps/#{app_name.underscore}"
95
+ app_class = Apps.const_get(app_name)
96
+ if app_class.is_a?(Class)
97
+ @app_class = app_class
98
+ else
99
+ @app_class = nil
100
+ end
101
+ end
102
+ rescue
103
+ @app_class = nil
104
+ end
105
+ end
106
+
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,51 @@
1
+ module Page::Utils
2
+ class PageNode
3
+
4
+ def self.build(page_instance, &block)
5
+ node = PageNode.new(page_instance)
6
+ node.instance_eval(&block)
7
+ node.hash
8
+ end
9
+
10
+ attr_reader :hash
11
+
12
+ def initialize(page_instance)
13
+ @hash = {}
14
+ @node_start_id = 0
15
+ @page_instance = page_instance
16
+ page_instance.instance_variables.each do |page_instance_var_key|
17
+ self.instance_variable_set(page_instance_var_key, page_instance.instance_variable_get(page_instance_var_key))
18
+ end
19
+ end
20
+
21
+ def method_missing meth, *args, &block
22
+ begin
23
+ @page_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 == :partial
34
+ @hash[current_node]["components"] = @page_instance.send(args.first, *args.drop(1))
35
+ else
36
+ if args.first.is_a?(Hash)
37
+ @hash[current_node]["config"] = args.first
38
+ else
39
+ @hash[current_node]["argument"] = args.first
40
+ end
41
+
42
+ if block_given?
43
+ @hash[current_node]["components"] = PageNode.build(@page_instance, &block)
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ %div{"id": component_id, "class": "page_content"}
2
+ %div
3
+ %div{"v-if": "asyncTemplate == null"}
4
+ - @children_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
+ %div{"id": page_id}
2
+ - @cells.each do |key, cell|
3
+ = cell.call(:show)
@@ -0,0 +1,5 @@
1
+ module Partial::Cell
2
+ class Partial < Component::Cell::Static
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %div{"id": component_id}
2
+ - @children_cells.each do |key, cell|
3
+ = cell.call(:show)
@@ -0,0 +1,10 @@
1
+ module Plain::Cell
2
+ class Plain < Component::Cell::Static
3
+
4
+ def show
5
+ @argument
6
+ end
7
+
8
+ end
9
+
10
+ end
@@ -0,0 +1,5 @@
1
+ module Section::Cell
2
+ class Section < Component::Cell::Static
3
+
4
+ end
5
+ end