asbru 0.0.9 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10f68d4052614b4607afdfc06092f1cca7b1c30bc6c887fb495f4eefc82dfafd
4
- data.tar.gz: 7ee326d3b5185d510042f8aaf5453a4351d39feb19a0239c3f98e87e7ac99239
3
+ metadata.gz: 392e033f6644c63cc44f180b0e6d5ad6544db1c1045a7ed6f214e58053d49e84
4
+ data.tar.gz: 36579ffc30c7b237a3d4610089fe68db7b530b13e1da8e67f0ff785ed12450ab
5
5
  SHA512:
6
- metadata.gz: 4202a50c75d6d622f096371ba25bee957c03d3a45482af3183d46716798173f88e3b98f1cb4aa9ccb74a315c0fd11feed697e6968cd3bb9aec9c2e0c9b17c3db
7
- data.tar.gz: 2326874f64e8ae9d1baa85c1ee7a7c3afb4e399be70e6849249ecd1c0fd6b21e14ae6296986ff809c975949ccd4c40ff730d4e4ad48bc7d792af0e0983a56024
6
+ metadata.gz: 85318b00ed09b9e5de6c81526c1d3782a6f0a9f9f6d1028d17c02a1ca0e2abe83409be931dc509abc144a7f11f4f4706dcadc1f091c6d27c12e4fcd9c3eb4d7d
7
+ data.tar.gz: e5e5a20151b86106c7b021f80ad5b5a2c4f100620ae098c5f5665f6b4d324d07032e692c3f611322585762084716bb190cf74b9657ef1c699efa864a9abf46ad
data/lib/asbru/cml.rb CHANGED
@@ -1,88 +1,65 @@
1
1
  require 'asbru/components/savage'
2
2
 
3
3
  module Asbru
4
- # This module defines a bunch of methods that
5
- module CML
6
- C = Asbru::Components::Savage
4
+ # This module defines a bunch of methods that make component based pages
5
+ # appear more similar to HTML.
6
+ # The limitation is that nested components won't work.
7
+ module Cml
8
+ C = Asbru::Config.component_mode.tap(&:setup)
7
9
 
8
- # Problems:
9
- # How can we make this module work with Sage/Savage depending on config?
10
- # Do we want to do that?
11
-
12
- # Ideas:
13
- # 1. We can make Sage implement to exactly the same interface as Savage and
14
- # somehow inject it.
15
- # 2. We could also ALWAYS load the sage classed needed here and call these
16
- # required.
17
- #
18
- # I think I prefer 1 even though the syntax of Sage is nicer imo.
19
10
  class << self
20
11
  def p text, **opts
21
- C.send "#{component_prefix}_content",
12
+ C.send "#{prefix(opts)}_content",
22
13
  text: text,
23
14
  **opts
24
15
  end
25
16
 
26
17
  def h1 text, **opts
27
- C.send "#{component_prefix}_title",
18
+ C.send "#{prefix(opts)}_title",
28
19
  size: 'h1',
29
20
  text: text
30
21
  end
31
22
 
32
23
  def h2 text, **opts
33
- C.send "#{component_prefix}_title",
24
+ C.send "#{prefix(opts)}_title",
34
25
  size: 'h2',
35
26
  text: text
36
27
  end
37
28
 
38
29
  def h3 text, **opts
39
- C.send "#{component_prefix}_title",
30
+ C.send "#{prefix(opts)}_title",
40
31
  size: 'h3',
41
32
  text: text
42
33
  end
43
34
 
44
35
  def h4 text, **opts
45
- C.send "#{component_prefix}_title",
36
+ C.send "#{prefix(opts)}_title",
46
37
  size: 'h4',
47
38
  text: text
48
39
  end
49
40
 
50
41
  def h5 text, **opts
51
- C.send "#{component_prefix}_title",
42
+ C.send "#{prefix(opts)}_title",
52
43
  size: 'h5',
53
44
  text: text
54
45
  end
55
46
 
56
- def hr color: 'stable-500'
57
- C.send "#{component_prefix}_divider",
47
+ def hr color: 'stable-500', **opts
48
+ C.send "#{prefix}_divider",
58
49
  color: color,
59
50
  height: 1
60
51
  end
61
52
 
62
- def vertical_spacer height
63
- C.send "#{component_prefix}_divider",
53
+ def vertical_spacer height, **opts
54
+ C.send "#{prefix(opts)}_divider",
64
55
  color: :transparent,
65
56
  height: height
66
57
  end
67
58
 
68
- def table_row(*cells)
69
- { data: cells }
70
- end
71
-
72
- def table_cell(text, action: nil, method: nil, confirm: nil, color: nil)
73
- cell = { text: text}
74
- cell[:color] = color if color.present?
75
- cell[:action] = action if action.present?
76
- cell[:customData] = {}
77
- cell[:customData]['data-method'] = method if method.present?
78
- cell[:customData]['data-confirm'] = confirm if confirm.present?
79
- cell
80
- end
81
-
82
59
  private
83
60
 
84
- def component_prefix
85
- Asbru.config.component_prefix
61
+ def prefix(opts)
62
+ opts[:module] || Asbru.config.component_prefix
86
63
  end
87
64
  end
88
65
  end
@@ -1,3 +1,5 @@
1
+ require 'react/rails/view_helper'
2
+
1
3
  module Asbru
2
4
  module Components
3
5
  # This module uses components.json to see what components are available to
@@ -9,6 +11,7 @@ module Asbru
9
11
  extend ::React::Rails::ViewHelper
10
12
  class << self
11
13
  def setup
14
+ debugger
12
15
  file = File.open(Rails.root.join('app',
13
16
  'javascript',
14
17
  'components',
@@ -1,3 +1,5 @@
1
+ require 'react/rails/view_helper'
2
+
1
3
  module Asbru
2
4
  module Components
3
5
  # This module is used to generate react components in the views and loads
@@ -6,6 +8,10 @@ module Asbru
6
8
  class Savage
7
9
  extend ::React::Rails::ViewHelper
8
10
  class << self
11
+ def setup
12
+ # No-op
13
+ end
14
+
9
15
  def method_missing(method_id, **opts)
10
16
  if self.respond_to? :method_id
11
17
  super
@@ -35,7 +35,7 @@ module Asbru
35
35
  { check_box: { type: 'checkbox' } },
36
36
  { file_field: { type: 'file' } },
37
37
  { text_field: {} },
38
- { telephone_field: { type: 'tel '}}
38
+ { telephone_field: { type: 'tel'}}
39
39
  ].freeze
40
40
 
41
41
  def errors(name)
@@ -45,20 +45,12 @@ module Asbru
45
45
  end
46
46
  end
47
47
 
48
- def tag_name_for(method, multiple = false)
49
- name = ActionView::Helpers::Tags::TextField.new(object_name,
50
- method, {})
51
- .send(:tag_name)
52
- name += '[]' if multiple
53
- name
54
- end
55
-
56
48
  def render_form_element(attribute, options)
57
49
  new_options = options.reverse_merge(
58
50
  {
59
51
  name: tag_name_for(attribute),
60
52
  errors: errors(attribute),
61
- errorIcon: error_icon
53
+ errorIcon: error_icon,
62
54
  }
63
55
  )
64
56
 
@@ -122,12 +114,77 @@ module Asbru
122
114
  end
123
115
  end
124
116
 
117
+ # def submit(attribute = nil, options = {})
118
+ # render_form_element attribute,
119
+ # options.reverse_merge(text: 'Submit', type: 'submit')
120
+ # end
121
+
122
+ # def date_field(attribute = nil, options = {})
123
+ # render_form_element attribute,
124
+ # options.reverse_merge(type: 'datepicker')
125
+ # end
126
+
127
+ # def password_field(attribute = nil, options = {})
128
+ # render_form_element attribute,
129
+ # options.reverse_merge(type: 'password')
130
+ # end
131
+
132
+ # def text_area(attribute = nil, options = {})
133
+ # render_form_element attribute,
134
+ # options.reverse_merge(type: 'textarea')
135
+ # end
136
+
137
+ # def email_field(attribute = nil, options = {})
138
+ # render_form_element attribute,
139
+ # options.reverse_merge(type: 'email')
140
+ # end
141
+
142
+ # def check_box(attribute = nil, options = {})
143
+ # render_form_element attribute,
144
+ # options.reverse_merge(type: 'check_box')
145
+ # end
146
+
147
+ # def text_field(attribute = nil, options = {})
148
+ # render_form_element attribute, options
149
+ # end
150
+
151
+ # def telephone_field
152
+ # render_form_element attribute,
153
+ # options.reverse_merge(type: 'tel')
154
+ # end
155
+
125
156
  BASIC_FORM_FIELDS.each do |item|
126
157
  define_method item.keys.first do |attribute = nil, options = {}|
127
158
  render_form_element(attribute, options.reverse_merge(item.values.first))
128
159
  end
129
160
  end
130
161
 
162
+ def file_field(attribute = nil, options = {})
163
+ options = { name: tag_name_for(attribute),
164
+ errors: errors(attribute),
165
+ errorIcon: error_icon,
166
+ type: 'file',
167
+ **options
168
+ }
169
+ if @object.present? && attribute.present?
170
+ options[:label] ||= I18n.t(attribute,
171
+ scope: "activerecord.attributes.#{@object.class.name.downcase}")
172
+
173
+ attachment = @object.send(attribute)
174
+ if attachment.present?
175
+ options['incommingFile'] = {
176
+ name: attachment.filename,
177
+ size: attachment.send('byte_size'),
178
+ type: attachment.content_type
179
+ }
180
+ end
181
+ end
182
+
183
+ Asbru::Components::Savage.send "#{Asbru.config.form_builder_prefix}_element",
184
+ **options
185
+ end
186
+
187
+
131
188
  def collection_radio_buttons(attribute,
132
189
  collection,
133
190
  value_method,
@@ -217,5 +274,13 @@ module Asbru
217
274
  def error_icon
218
275
  Asbru.config.default_form_error_icon
219
276
  end
277
+
278
+ def tag_name_for(method, multiple = false)
279
+ name = ActionView::Helpers::Tags::TextField.new(object_name,
280
+ method, {})
281
+ .send(:tag_name)
282
+ name += '[]' if multiple
283
+ name
284
+ end
220
285
  end
221
286
  end
data/lib/asbru/ragna.rb CHANGED
@@ -5,8 +5,8 @@ require 'asbru/cml'
5
5
 
6
6
  # We use the C for binding components. We might want to make this configurable
7
7
  # later on
8
- ::C = Asbru::Components::Sage.tap(&:setup)
9
- ::CML = Asbru::CML
8
+ ::C = Asbru.config.component_mode.tap(&:setup)
9
+ ::Cml = Asbru::Cml
10
10
 
11
11
  module Asbru
12
12
  module Ragna
data/lib/asbru/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Asbru
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.12'
3
3
  end
data/lib/asbru.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require "asbru/railtie"
2
2
  require 'dry-configurable'
3
+ require 'asbru/components/savage'
4
+ require 'asbru/components/sage'
3
5
 
4
6
  module Asbru
5
7
  extend Dry::Configurable
6
8
  setting :component_prefix, default: 'app'
7
9
  setting :form_builder_prefix, default: 'app'
8
10
  setting :default_form_error_icon, default: 'icon-error'
11
+ setting :component_mode, default: Asbru::Components::Savage
12
+
13
+ Config = self.config
9
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asbru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stev-0
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-25 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails