coprl 3.0.0.beta.5 → 3.0.0.beta.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +11 -16
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +36 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +35 -39
  7. data/README.md +3 -3
  8. data/app/demo/components/snackbar.pom +9 -3
  9. data/coprl.gemspec +1 -2
  10. data/lib/coprl/presenters/api/app.rb +7 -2
  11. data/lib/coprl/presenters/dsl/components/base.rb +0 -1
  12. data/lib/coprl/presenters/dsl/definition.rb +2 -2
  13. data/lib/coprl/presenters/dsl/user_interface.rb +2 -2
  14. data/lib/coprl/presenters/helpers/rails/routes.rb +14 -0
  15. data/lib/coprl/presenters/helpers/rails.rb +8 -6
  16. data/lib/coprl/presenters/rails/concerns/coprl_partial.rb +51 -0
  17. data/lib/coprl/presenters/rails/engine.rb +5 -0
  18. data/lib/coprl/presenters/rails/railtie.rb +6 -14
  19. data/lib/coprl/presenters/rails/reloader.rb +15 -0
  20. data/lib/coprl/presenters/version.rb +1 -1
  21. data/lib/coprl/presenters/web_client/helpers/headers.rb +8 -6
  22. data/lib/coprl/presenters/web_client/helpers/rails/template_helper.rb +10 -0
  23. data/lib/coprl/presenters/web_client/helpers/rails.rb +1 -0
  24. data/lib/coprl/presenters/web_client/helpers/sinatra/template_helper.rb +20 -0
  25. data/lib/coprl/presenters/web_client/helpers/sinatra.rb +1 -0
  26. data/lib/coprl/presenters/web_client/plugin_views_path.rb +5 -5
  27. data/rails-engine/app/controllers/coprl_controller.rb +0 -17
  28. data/rails-engine/app/views/layouts/coprl.html.erb +4 -4
  29. data/rails-engine/config/initializers/presenters.rb +4 -2
  30. data/rails-engine/config/initializers/routes.rb +5 -0
  31. data/views/mdc/body/{_preamble.erb → _wrapper.erb} +16 -5
  32. data/views/mdc/components/buttons/_image.erb +1 -1
  33. data/views/mdc/layout.erb +4 -4
  34. metadata +16 -26
  35. data/app/demo/components/snackbar_attached.pom +0 -6
  36. data/views/mdc/body/_postamble.erb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff1d61921712f73e4c13f6a206c4499e7bd72f40b82471cf03f741a272f118c1
4
- data.tar.gz: 6e6812e4334f47c542b3710cea1d74daa0d6f7b3e803bd0ac334e15cc6192461
3
+ metadata.gz: 236ae7548578c302ec736e18f4bc4542d37548f4a6f6cea794b80eadb263c61d
4
+ data.tar.gz: 44da31446c80059812b1839d53ddc36d91d95d8db1ac5f8c09738aae34f9da69
5
5
  SHA512:
6
- metadata.gz: 384f80e03ad8cb9674d35d3fb5ceb293b6fed3c4b497076efeb3dfd8215394716b6c82db4fc8fc5ffe8d8145a6bc6f5f69adbcd6ecf67245f5f9e7b08c2cdb81
7
- data.tar.gz: 15ec4d677bc0ab317e5de06c3c0e499fa22b9fa047c78da589539365e6abc4c8dce33a889d97e6d9f620916ceaf05eb2dc1ec89ad29b9eab1828dfccde9dd15f
6
+ metadata.gz: c417061bb470e7a028d82b9e699e60c96b24fee025f8fcd16c2301841ac913b6da140dad47a23c8ed7d814cf25044b2a517aff76e9e2720cc0c1bbdb5821d0a7
7
+ data.tar.gz: cde447a1e215f53bf2aec0854cac8611b05db11d49b2596a52ec1f13bd27249a84e73147a7f375a190e0bc445f17fb1508b033b3b0ad3812fa7e638772dfc3ee
data/.circleci/config.yml CHANGED
@@ -7,7 +7,7 @@ jobs:
7
7
  build:
8
8
  docker:
9
9
  # specify the version you desire here
10
- - image: circleci/ruby:2.7.2-node-browsers
10
+ - image: circleci/ruby:2.7.4-node-browsers
11
11
 
12
12
  # Specify service dependencies here if necessary
13
13
  # CircleCI maintains a library of pre-built images
@@ -18,28 +18,23 @@ jobs:
18
18
 
19
19
  steps:
20
20
  - checkout
21
-
22
- # Download and cache dependencies
23
21
  - restore_cache:
24
22
  keys:
25
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
- # fallback to using the latest cache if no exact match is found
27
- - v1-dependencies-
28
-
29
- - run:
30
- name: install dependencies
31
- command: |
32
- bundle install --jobs=4 --retry=3 --path vendor/bundle
33
-
23
+ # when lock file changes, use increasingly general patterns to restore cache
24
+ - v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
25
+ - v1-gem-cache-{{ arch }}-{{ .Branch }}-
26
+ - v1-gem-cache-{{ arch }}-
27
+ - run: gem install bundler:2.2.20
28
+ - run: bundle install
29
+ - run: bundle clean --force
34
30
  - save_cache:
35
31
  paths:
36
- - ./vendor/bundle
37
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
-
32
+ - ~/.bundle
33
+ key: v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
39
34
  - run:
40
35
  name: 'start integration testing server'
41
36
  command: |
42
- rackup
37
+ bundle exec rackup
43
38
  background: true
44
39
 
45
40
  # run tests!
data/.ruby-version CHANGED
@@ -1,2 +1,2 @@
1
- 2.7.2
1
+ 2.7.4
2
2
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,39 @@
1
+ # [3.0.0-beta.9](https://github.com/rx/presenters/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-09-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * added support for api base base_url ([8f69979](https://github.com/rx/presenters/commit/8f699793de899a450df5cfb8b95015a832200178))
7
+ * fixed bug in context prep for api client ([d0558cf](https://github.com/rx/presenters/commit/d0558cf3966a9bdc91bd9d106dcb0a7ab6f56c34))
8
+
9
+ # [3.0.0-beta.8](https://github.com/rx/presenters/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-09-17)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * added check for engine coprl_presenters_rails_engine_url ([d2ee7b5](https://github.com/rx/presenters/commit/d2ee7b5900a256c30e6715d1246639dec682ff08))
15
+
16
+ # [3.0.0-beta.7](https://github.com/rx/presenters/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-07-09)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * Rails routes automatically made available as helpers ([#322](https://github.com/rx/presenters/issues/322)) ([abb0031](https://github.com/rx/presenters/commit/abb00311940fda8741459f8aafe29cd7bf074b88))
22
+ * view paths issue when using partials with Rails Engine ([#321](https://github.com/rx/presenters/issues/321)) ([2a917e7](https://github.com/rx/presenters/commit/2a917e7076895037e5a069e77525ef53d2ca45f1))
23
+
24
+
25
+ ### Features
26
+
27
+ * switch to use Rails built-in watchers and reloader ([#320](https://github.com/rx/presenters/issues/320)) ([53e0ee4](https://github.com/rx/presenters/commit/53e0ee49caa663ce93ff731c280bcd754da73fc1))
28
+
29
+ # [3.0.0-beta.6](https://github.com/rx/presenters/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-06-23)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * fixed typo on if check ([95b3091](https://github.com/rx/presenters/commit/95b3091365a853eee24e4bce0e37b182da1fdc3d))
35
+ * small tweaks to simplify the presenters wrappers ([#319](https://github.com/rx/presenters/issues/319)) ([cbf0c7c](https://github.com/rx/presenters/commit/cbf0c7c4c80d68ecc84a2989934d2d02e8a1a928))
36
+
1
37
  # [3.0.0-beta.5](https://github.com/rx/presenters/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-06-18)
2
38
 
3
39
 
data/Gemfile CHANGED
@@ -13,7 +13,7 @@ end
13
13
  group :test do
14
14
  gem 'rspec'
15
15
  gem 'rspec-html-matchers'
16
- gem 'watir', '~> 6.16'
16
+ gem 'watir', '~> 6.19'
17
17
  gem 'webdrivers', '~> 4.1'
18
18
  gem 'watir-rspec', '~> 3.0'
19
19
  gem 'rspec_junit_formatter'
data/Gemfile.lock CHANGED
@@ -30,7 +30,7 @@ GIT
30
30
 
31
31
  GIT
32
32
  remote: https://github.com/coprl/foo_presenter_plugin.git
33
- revision: 7b05a88ac5d34a18401d8dbbb73758927be39cdd
33
+ revision: 6f1d796bf030bf69fca87777d28bdee63e9880d8
34
34
  specs:
35
35
  foo_presenter_plugin (0.0.2)
36
36
 
@@ -80,11 +80,10 @@ GIT
80
80
  PATH
81
81
  remote: .
82
82
  specs:
83
- coprl (1.0.0)
83
+ coprl (3.0.0.beta.8)
84
84
  dry-configurable (> 0.1, <= 7.0)
85
85
  dry-container (~> 0.6)
86
86
  dry-inflector (~> 0.1)
87
- filewatcher (~> 1.1.1)
88
87
  ice_nine (~> 0.11)
89
88
  redcarpet (~> 3.4)
90
89
  sinatra (>= 1.4, < 3.0)
@@ -99,34 +98,30 @@ GEM
99
98
  childprocess (3.0.0)
100
99
  coderay (1.1.2)
101
100
  concurrent-ruby (1.1.9)
102
- diff-lcs (1.3)
101
+ diff-lcs (1.4.4)
103
102
  docile (1.3.1)
104
103
  dotenv (2.7.6)
105
- dry-configurable (0.12.1)
104
+ dry-configurable (0.13.0)
106
105
  concurrent-ruby (~> 1.0)
107
- dry-core (~> 0.5, >= 0.5.0)
108
- dry-container (0.8.0)
106
+ dry-core (~> 0.6)
107
+ dry-container (0.9.0)
109
108
  concurrent-ruby (~> 1.0)
110
- dry-configurable (~> 0.1, >= 0.1.3)
111
- dry-core (0.6.0)
109
+ dry-configurable (~> 0.13, >= 0.13.0)
110
+ dry-core (0.7.1)
112
111
  concurrent-ruby (~> 1.0)
113
- dry-inflector (0.2.0)
114
- filewatcher (1.1.1)
115
- optimist (~> 3.0)
116
- gem-release (2.0.1)
112
+ dry-inflector (0.2.1)
117
113
  ice_nine (0.11.2)
118
114
  json (2.3.1)
119
115
  method_source (0.9.0)
120
- mini_portile2 (2.5.1)
116
+ mini_portile2 (2.5.3)
121
117
  mustermann (1.1.1)
122
118
  ruby2_keywords (~> 0.0.1)
123
119
  nio4r (2.5.7)
124
- nokogiri (1.11.4)
120
+ nokogiri (1.11.7)
125
121
  mini_portile2 (~> 2.5.0)
126
122
  racc (~> 1.4)
127
- nokogiri (1.11.4-x86_64-darwin)
123
+ nokogiri (1.11.7-x86_64-darwin)
128
124
  racc (~> 1.4)
129
- optimist (3.0.1)
130
125
  pry (0.11.3)
131
126
  coderay (~> 1.1.0)
132
127
  method_source (~> 0.9.0)
@@ -145,27 +140,27 @@ GEM
145
140
  rack (>= 1.0, < 3)
146
141
  rake (13.0.1)
147
142
  redcarpet (3.5.1)
148
- regexp_parser (1.6.0)
149
- rspec (3.8.0)
150
- rspec-core (~> 3.8.0)
151
- rspec-expectations (~> 3.8.0)
152
- rspec-mocks (~> 3.8.0)
153
- rspec-core (3.8.2)
154
- rspec-support (~> 3.8.0)
155
- rspec-expectations (3.8.4)
143
+ regexp_parser (2.1.1)
144
+ rspec (3.10.0)
145
+ rspec-core (~> 3.10.0)
146
+ rspec-expectations (~> 3.10.0)
147
+ rspec-mocks (~> 3.10.0)
148
+ rspec-core (3.10.1)
149
+ rspec-support (~> 3.10.0)
150
+ rspec-expectations (3.10.1)
156
151
  diff-lcs (>= 1.2.0, < 2.0)
157
- rspec-support (~> 3.8.0)
152
+ rspec-support (~> 3.10.0)
158
153
  rspec-html-matchers (0.9.1)
159
154
  nokogiri (~> 1)
160
155
  rspec (>= 3.0.0.a, < 4)
161
- rspec-mocks (3.8.1)
156
+ rspec-mocks (3.10.2)
162
157
  diff-lcs (>= 1.2.0, < 2.0)
163
- rspec-support (~> 3.8.0)
164
- rspec-support (3.8.2)
158
+ rspec-support (~> 3.10.0)
159
+ rspec-support (3.10.2)
165
160
  rspec_junit_formatter (0.4.1)
166
161
  rspec-core (>= 2, < 4, != 2.12.0)
167
- ruby2_keywords (0.0.4)
168
- rubyzip (1.3.0)
162
+ ruby2_keywords (0.0.5)
163
+ rubyzip (2.3.0)
169
164
  selenium-webdriver (3.142.7)
170
165
  childprocess (>= 0.5, < 4.0)
171
166
  rubyzip (>= 1.2.2)
@@ -183,19 +178,20 @@ GEM
183
178
  tilt (~> 2.0)
184
179
  thor (1.1.0)
185
180
  tilt (2.0.10)
181
+ timecop (0.9.4)
186
182
  tzinfo (2.0.4)
187
183
  concurrent-ruby (~> 1.0)
188
184
  tzinfo-data (1.2021.1)
189
185
  tzinfo (>= 1.0.0)
190
- watir (6.16.5)
191
- regexp_parser (~> 1.2)
192
- selenium-webdriver (~> 3.6)
186
+ watir (6.19.1)
187
+ regexp_parser (>= 1.2, < 3)
188
+ selenium-webdriver (>= 3.142.7)
193
189
  watir-rspec (3.0.0)
194
190
  rspec (~> 3.0)
195
191
  watir (>= 6.0.0.beta4)
196
- webdrivers (4.1.0)
192
+ webdrivers (4.6.0)
197
193
  nokogiri (~> 1.6)
198
- rubyzip (~> 1.0)
194
+ rubyzip (>= 1.3.0)
199
195
  selenium-webdriver (>= 3.0, < 4.0)
200
196
  zeitwerk (2.4.2)
201
197
 
@@ -213,7 +209,6 @@ DEPENDENCIES
213
209
  coprl!
214
210
  dotenv
215
211
  foo_presenter_plugin!
216
- gem-release (~> 2.0)
217
212
  google_maps_presenter_plugin!
218
213
  iframe_presenter_plugin!
219
214
  image_crop_presenter_plugin!
@@ -233,13 +228,14 @@ DEPENDENCIES
233
228
  shotgun (~> 0.9)
234
229
  simplecov
235
230
  thor (~> 1.1.0)
231
+ timecop (~> 0.9.4)
236
232
  timer_presenter_plugin!
237
- watir (~> 6.16)
233
+ watir (~> 6.19)
238
234
  watir-rspec (~> 3.0)
239
235
  webdrivers (~> 4.1)
240
236
 
241
237
  RUBY VERSION
242
- ruby 2.7.2p137
238
+ ruby 2.7.4p191
243
239
 
244
240
  BUNDLED WITH
245
241
  2.2.20
data/README.md CHANGED
@@ -101,13 +101,13 @@ You need to add the following to your layout to use presenters as a partial alon
101
101
  ##### Inside the &lt;head&gt; tag add the following:
102
102
 
103
103
  <title><%= @pom.page.title if @pom.page %></title>
104
- <%= coprl_headers(@base_url, request, @pom) %>
104
+ <%= coprl_headers %>
105
105
 
106
106
  ##### Inside the &lt;body&gt; tag, around you existing yield add the following:
107
107
 
108
- <%= partial "body/preamble", :locals => {pom:@pom} %>
108
+ <%= with_presenters_wrapper do %>
109
109
  <%= yield %>
110
- <%= partial "body/postamble", :locals => {pom:@pom} %>
110
+ <%= end %>
111
111
 
112
112
  ### Rack
113
113
  #### 1) To use it, add this line to your Gemfile:
@@ -8,10 +8,10 @@ Coprl::Presenters.define(:snackbar) do
8
8
 
9
9
  indented_grid do
10
10
  title 'On Page'
11
- body 'You can attach a snackbar on the server side and will render after load.'
11
+ body 'You can invoke or attach a snackbar on the server side and will render after load.'
12
12
  snackbar 'Top Level Important Information!'
13
-
14
- attach :snackbar_attached
13
+ # This is the same as above -- see POM at end of file
14
+ # attach :snackbar_attached
15
15
 
16
16
  title 'As Event'
17
17
  button 'Show Snackbar', id: :show_snackbar do
@@ -33,3 +33,9 @@ Coprl::Presenters.define(:snackbar) do
33
33
 
34
34
  attach :code, file: __FILE__
35
35
  end
36
+
37
+ # Coprl::Presenters.define(:snackbar_attached) do
38
+ # title 'In Attached'
39
+ # body 'This can be done in an attached presenter as well'
40
+ # snackbar 'Attached Snackbar Displayed!'
41
+ # end
data/coprl.gemspec CHANGED
@@ -28,7 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_runtime_dependency 'tzinfo', '>=1.1', '< 3.0'
29
29
  spec.add_runtime_dependency 'tzinfo-data', '~>1.2018'
30
30
  spec.add_runtime_dependency 'redcarpet', '~>3.4'
31
- spec.add_runtime_dependency 'filewatcher', '~> 1.1.1'
32
31
  spec.add_runtime_dependency 'zeitwerk', '~> 2.1'
33
32
 
34
33
  spec.add_development_dependency 'thor', '~> 1.1.0'
@@ -38,6 +37,6 @@ Gem::Specification.new do |spec|
38
37
  spec.add_development_dependency 'bundler', '>= 1.13'
39
38
  spec.add_development_dependency 'rake', '~> 13.0'
40
39
  spec.add_development_dependency 'rspec', '~> 3.0'
41
- spec.add_development_dependency 'gem-release', '~> 2.0'
42
40
  spec.add_development_dependency 'shotgun', '~> 0.9'
41
+ spec.add_development_dependency 'timecop', '~> 0.9.4 '
43
42
  end
@@ -66,9 +66,9 @@ module Coprl
66
66
 
67
67
  def prepare_context(base_params = params)
68
68
  prepare_context = Presenters::Settings.config.presenters.web_client.prepare_context.dup
69
- prepare_context.push(method(:scrub_context))
69
+ prepare_context.push(method(:scrub_context)).push(method(:base_url_context))
70
70
  context = base_params.dup
71
- prepare_context.reduce(context) do |params, context_proc|
71
+ context = prepare_context.reduce(context) do |params, context_proc|
72
72
  context_proc.call(params, session, env)
73
73
  end
74
74
  context
@@ -80,6 +80,11 @@ module Coprl
80
80
  end
81
81
  params
82
82
  end
83
+
84
+ def base_url_context(params, _session, env)
85
+ params[:base_url] = "#{request.base_url}#{env['SCRIPT_NAME']}"
86
+ params
87
+ end
83
88
  end
84
89
  end
85
90
  end
@@ -75,7 +75,6 @@ module Coprl
75
75
 
76
76
  alias params context
77
77
 
78
-
79
78
  def yield_block
80
79
  return @_yield_block_ if @_yield_block_
81
80
  @parent.send(:yield_block)
@@ -17,8 +17,8 @@ module Coprl
17
17
  self
18
18
  end
19
19
 
20
- def expand(router: , context:{}, &block)
21
- presenter = UserInterface.new(router: router, context: context, name: @name, namespace: @namespace, &@block)
20
+ def expand(router: , context:{}, plugins: [], &block)
21
+ presenter = UserInterface.new(router: router, context: context, plugins: plugins, name: @name, namespace: @namespace, &@block)
22
22
  yield(presenter) if block
23
23
  presenter.expand_instance
24
24
  end
@@ -25,7 +25,7 @@ module Coprl
25
25
  private :context, :router, :namespace
26
26
  alias params context
27
27
 
28
- def initialize(context:, parent: nil, router: nil, name: nil, namespace: [], &block)
28
+ def initialize(context:, parent: nil, router: nil, name: nil, plugins: [], namespace: [], &block)
29
29
  @parent = parent
30
30
  @router = router || @parent&.send(:router)
31
31
  @context = context || {}
@@ -36,7 +36,7 @@ module Coprl
36
36
  @footer = nil
37
37
  @name = name
38
38
  @namespace = namespace
39
- @plugins = []
39
+ @plugins = plugins || []
40
40
  @csrf_meta_tags = authenticity_token_meta_tags(@context.fetch(:session, nil))
41
41
  add_global_helpers
42
42
  initialize_plugins
@@ -0,0 +1,14 @@
1
+ module Coprl
2
+ module Presenters
3
+ module Helpers
4
+ module Rails
5
+ module Routes
6
+ include ::Rails.application.routes.url_helpers
7
+ def default_url_options
8
+ ::Rails.application.config.action_controller.default_url_options || { :host => context[:base_url] ? context[:base_url] : context[:request].host_with_port }
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,18 +6,20 @@ if defined?(Rails)
6
6
  include ActionView::Helpers::AssetUrlHelper
7
7
  include Coprl::Presenters::Helpers::Rails::Currency
8
8
  include Coprl::Presenters::Helpers::Rails::ModelTable
9
+ include Coprl::Presenters::Helpers::Rails::Routes
9
10
  include Namespace
10
11
 
11
- def default_url_options
12
- {}
13
- end
14
-
15
12
  def presenters_path(presenter, host: false, **params)
16
13
  presenter = _expand_namespace_(presenter, namespace)
17
14
  presenter = presenter.gsub(':', '/')
18
15
 
19
- path = host ? coprl_presenters_web_client_app_url(params, host: router.base_url) :
20
- coprl_presenters_web_client_app_path(params)
16
+ path = if defined?(coprl_presenters_rails_engine_url)
17
+ host ? coprl_presenters_rails_engine_url(params, host: router.base_url) :
18
+ coprl_presenters_rails_engine_path(params)
19
+ else
20
+ host ? coprl_presenters_web_client_app_url(params, host: router.base_url) :
21
+ coprl_presenters_web_client_app_path(params)
22
+ end
21
23
 
22
24
  if path.include?('?')
23
25
  path = path.sub('?', "#{presenter}?")
@@ -0,0 +1,51 @@
1
+ module Coprl
2
+ module Presenters
3
+ module Rails
4
+ module Concerns
5
+ module CoprlPartial
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before_action :set_view_path
10
+ end
11
+
12
+ module ClassMethods
13
+ @plugins = []
14
+ def presenter_plugin(*plugins)
15
+ @plugins += Array(plugins)
16
+ end
17
+
18
+ def plugins
19
+ @plugins
20
+ end
21
+ end
22
+
23
+ def set_view_path
24
+ paths = Coprl::Presenters::WebClient::PluginViewsPath.new(pom: nil, plugins: self.class.plugins).render
25
+ paths.each do |path|
26
+ prepend_view_path path
27
+ end
28
+ end
29
+
30
+ def prepare_context(base_params = params)
31
+ prepare_context = Coprl::Presenters::Settings.config.presenters.web_client.prepare_context.dup
32
+ prepare_context.push(method(:scrub_context))
33
+ context = base_params.dup.to_unsafe_hash
34
+ prepare_context.reduce(context) do |params, context_proc|
35
+ context = context_proc.call(params, session, request.env)
36
+ end
37
+ context
38
+ end
39
+
40
+ def scrub_context(params, _session, _env)
41
+ %i(grid_nesting input_tag).each do |key|
42
+ params.delete(key) {params.delete(key.to_s)}
43
+ end
44
+ params
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -12,6 +12,11 @@ module Coprl
12
12
  # TODO: should rename these since they are common names that are likely going to collide
13
13
  app.middleware.use ::ActionDispatch::Static, File.join(root, '..', 'public')
14
14
  end
15
+
16
+ ActiveSupport.on_load(:action_controller) do
17
+ include Concerns::CoprlPartial
18
+ end
19
+
15
20
  end
16
21
  end
17
22
  end
@@ -1,5 +1,3 @@
1
- require 'filewatcher'
2
-
3
1
  module Coprl
4
2
  module Presenters
5
3
  module Rails
@@ -15,20 +13,14 @@ module Coprl
15
13
 
16
14
  WATCH = -> {
17
15
  return unless ::Rails.env.development?
16
+
18
17
  path = ::Rails.root.join('app', '**', '*.pom')
19
- puts "Watching #{path} for changes..."
20
- filewatcher = Filewatcher.new(path)
21
- Thread.new(filewatcher) do |fw|
22
- fw.watch do |f|
23
- puts "Detected updated POM file: #{f}"
24
- begin
25
- BOOT.call
26
- rescue Exception => exc
27
- puts exc.backtrace
28
- puts exc.message
29
- end
30
- end
18
+ file_watcher = ActiveSupport::FileUpdateChecker.new(Dir[path]) do
19
+ BOOT.call
31
20
  end
21
+
22
+ ::Rails.application.reloaders << Reloader.new(file_watcher)
23
+
32
24
  } unless defined?(WATCH)
33
25
 
34
26
  config.after_initialize do
@@ -0,0 +1,15 @@
1
+ module Coprl
2
+ module Presenters
3
+ module Rails
4
+ class Reloader
5
+ def initialize(file_watcher)
6
+ @file_watcher = file_watcher
7
+ end
8
+
9
+ def updated?
10
+ @file_watcher.execute_if_updated
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  module Coprl
2
2
  module Presenters
3
3
  module Version
4
- VERSION = '3.0.0.beta.5'
4
+ VERSION = '3.0.0.beta.9'
5
5
  end
6
6
  end
7
7
  end
@@ -2,16 +2,18 @@ module Coprl::Presenters::WebClient::Helpers
2
2
  module Headers
3
3
  include Coprl::Presenters::WebClient::Helpers::HtmlSafe
4
4
 
5
- def coprl_headers(base_url, request, pom)
5
+ def coprl_headers
6
+ return unless @pom
7
+
6
8
  html_safe (<<~HEADERS)
7
9
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">
8
10
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
9
11
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
10
- <link rel="stylesheet" href="#{ base_url }/#{ request.env['SCRIPT_NAME'] }bundle.css">
11
- <script defer src="#{ base_url }/#{ request.env['SCRIPT_NAME'] }bundle.js"></script>
12
- #{plugin_headers(pom)}
13
- #{custom_css(request.env['REQUEST_PATH'], base_url)}
14
- #{pom.csrf_meta_tags}
12
+ <link rel="stylesheet" href="#{ @base_url }/#{ request.env['SCRIPT_NAME'] }bundle.css">
13
+ <script defer src="#{ @base_url }/#{ request.env['SCRIPT_NAME'] }bundle.js"></script>
14
+ #{plugin_headers(@pom)}
15
+ #{custom_css(request.env['REQUEST_PATH'], @base_url)}
16
+ #{@pom.csrf_meta_tags}
15
17
  HEADERS
16
18
  end
17
19
 
@@ -0,0 +1,10 @@
1
+ module Coprl::Presenters::WebClient::Helpers::Rails
2
+ module TemplateHelper
3
+ def with_presenters_wrapper(&block)
4
+ render partial: 'body/wrapper', locals: {
5
+ body_content: capture(&block), header: @pom&.header, drawer: @pom&.drawer,
6
+ footer: @pom&.footer
7
+ }
8
+ end
9
+ end
10
+ end
@@ -8,5 +8,6 @@ module Coprl::Presenters::WebClient::Helpers
8
8
  include Namespaced
9
9
  include Raw
10
10
  include EscapeHtml
11
+ include TemplateHelper
11
12
  end
12
13
  end
@@ -0,0 +1,20 @@
1
+ module Coprl::Presenters::WebClient::Helpers::Sinatra
2
+ module TemplateHelper
3
+ def with_presenters_wrapper(&block)
4
+ buffer << partial("body/wrapper", locals: {
5
+ body_content: capture(buffer, &block), header: @pom&.header, drawer: @pom&.drawer,
6
+ footer: @pom&.footer
7
+ })
8
+ end
9
+
10
+ def buffer()
11
+ @_out_buf
12
+ end
13
+
14
+ def capture(buffer)
15
+ pos = buffer.size
16
+ yield
17
+ buffer.slice!(pos..buffer.size)
18
+ end
19
+ end
20
+ end
@@ -7,5 +7,6 @@ module Coprl::Presenters::WebClient::Helpers
7
7
  include SafeMarkdown
8
8
  include Raw
9
9
  include EscapeHtml
10
+ include TemplateHelper
10
11
  end
11
12
  end
@@ -8,17 +8,17 @@ module Coprl
8
8
  extend Pluggable
9
9
  include_plugins(:WebClientComponents)
10
10
 
11
- def initialize(pom:)
11
+ def initialize(pom: nil, plugins: nil)
12
12
  @pom = pom
13
+ @plugins = plugins || []
13
14
  initialize_plugins
14
15
  end
15
16
 
16
17
  def render
17
18
  results = []
18
- ((@plugins||[]) + Coprl::Presenters::Settings.config.presenters.plugins).each do |plugin|
19
+ (@plugins + Coprl::Presenters::Settings.config.presenters.plugins).each do |plugin|
19
20
  view_dir_method = :"view_dir_#{plugin}"
20
- results << send(view_dir_method,
21
- @pom) if respond_to?(view_dir_method)
21
+ results << send(view_dir_method, @pom) if respond_to?(view_dir_method)
22
22
  end
23
23
  results
24
24
  end
@@ -26,7 +26,7 @@ module Coprl
26
26
  private
27
27
 
28
28
  def initialize_plugins
29
- @plugins = @pom.send(:plugins)
29
+ @plugins += @pom.send(:plugins) if @pom
30
30
  self.class.include_plugins(:WebClientComponents, plugins: @plugins)
31
31
  end
32
32
  end
@@ -23,21 +23,4 @@ class CoprlController < ApplicationController
23
23
  prepend_view_path path
24
24
  end
25
25
  end
26
-
27
- def prepare_context(base_params = params)
28
- prepare_context = Coprl::Presenters::Settings.config.presenters.web_client.prepare_context.dup
29
- prepare_context.push(method(:scrub_context))
30
- context = base_params.dup.to_unsafe_hash
31
- prepare_context.reduce(context) do |params, context_proc|
32
- context = context_proc.call(params, session, request.env)
33
- end
34
- context
35
- end
36
-
37
- def scrub_context(params, _session, _env)
38
- %i(grid_nesting input_tag).each do |key|
39
- params.delete(key) {params.delete(key.to_s)}
40
- end
41
- params
42
- end
43
26
  end
@@ -7,14 +7,14 @@
7
7
  <title><%= @pom.page.title if @pom.page %></title>
8
8
  <meta name="description" content="">
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1">
10
- <%= coprl_headers(@base_url, request, @pom) %>
10
+ <%= coprl_headers %>
11
11
  <%= csrf_meta_tags %>
12
12
  <%= csp_meta_tag if defined?(csp_meta_tag) %>
13
13
  </head>
14
14
  <body>
15
- <%= partial "body/preamble", :locals => {pom:@pom} %>
16
- <%= yield %>
17
- <%= partial "body/postamble", :locals => {pom:@pom} %>
15
+ <%= with_presenters_wrapper do %>
16
+ <%= yield %>
17
+ <% end %>
18
18
  <noscript><p>JavaScript must be enabled to continue.</p></noscript>
19
19
  </body>
20
20
  </html>
@@ -28,9 +28,11 @@ class CoprlTemplateHandler
28
28
  # otherwise we need to get the presenter name built from params
29
29
  presenter_name = local_assigns[:presenter] ? presenter : namespaced_presenter(params)
30
30
  presenter = Coprl::Presenters::App[presenter_name].call
31
- context = params.dup.to_unsafe_hash
31
+ context = self.controller.prepare_context(params)
32
32
  router = Coprl::Presenters::WebClient::Router.new(base_url: request.base_url)
33
- @pom = presenter.expand(router: router, context: context)
33
+ plugins = self.controller.class.plugins
34
+
35
+ @pom = presenter.expand(router: router, context: context, plugins: plugins)
34
36
  end
35
37
  #{source}
36
38
  end
@@ -0,0 +1,5 @@
1
+ Rails.application.config.to_prepare do
2
+ Coprl::Presenters::Settings.configure do |config|
3
+ config.presenters.helpers << Coprl::Presenters::Helpers::Rails
4
+ end
5
+ end
@@ -1,15 +1,10 @@
1
1
  <%
2
- header = pom.header
3
- drawer = pom.drawer
4
- footer = pom.footer
5
-
6
2
  root_classes = []
7
3
  root_classes << 'v-root--header-present' if header
8
4
  root_classes << 'v-root--drawer-present' if drawer
9
5
  root_classes << 'v-root--footer-present' if footer
10
6
  %>
11
7
  <div class="v-root compatibility-wrapper mdc-typography <%= root_classes.join(' ') %>">
12
-
13
8
  <% if drawer %>
14
9
  <div class="drawer-frame-root">
15
10
  <%= partial "body/dismissable-drawer", :locals => {drawer: drawer} %>
@@ -22,5 +17,21 @@
22
17
  <div class="drawer-main-content">
23
18
  <%= partial "body/modal-drawer", :locals => {drawer: drawer} %>
24
19
  <% end %>
20
+
21
+ <%= body_content %>
22
+
25
23
  <div class="v-page-content page-content">
26
24
  <div class="v-errors">
25
+ </div>
26
+ </div>
27
+ <% if drawer %>
28
+ </div>
29
+ </div>
30
+ </div>
31
+ <% end %>
32
+
33
+ <%= partial "body/snackbar" %>
34
+ <% if footer %>
35
+ <%= partial "body/footer", :locals => {:footer => footer} %>
36
+ <% end %>
37
+ </div>
@@ -22,4 +22,4 @@
22
22
  <%= partial "components/icon", :locals => {comp: comp.icon, class_name: 'mdc-button__icon', position: [:right, :center]} if comp.icon %>
23
23
  </button>
24
24
  <%= partial "components/tooltip", :locals => {comp: comp.tooltip, parent_id: comp.id} if comp.tooltip %>
25
- <%= partial "components/menu", :locals => {comp: comp.menu, parent_id: comp.id} if comp.menus %>
25
+ <%= partial "components/menu", :locals => {comp: comp.menu, parent_id: comp.id} if comp.menu %>
data/views/mdc/layout.erb CHANGED
@@ -7,12 +7,12 @@
7
7
  <title><%= @pom.page.title if @pom.page %></title>
8
8
  <meta name="description" content="">
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1">
10
- <%= coprl_headers(@base_url, request, @pom) %>
10
+ <%= coprl_headers %>
11
11
  </head>
12
12
  <body class="mdc-typography">
13
- <%= partial "body/preamble", :locals => {pom:@pom} %>
14
- <%= yield %>
15
- <%= partial "body/postamble", :locals => {pom:@pom} %>
13
+ <% with_presenters_wrapper do %>
14
+ <%= yield %>
15
+ <% end %>
16
16
  <noscript><p>JavaScript must be enabled to continue.</p></noscript>
17
17
  </body>
18
18
  </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coprl
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta.5
4
+ version: 3.0.0.beta.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Edens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-18 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ice_nine
@@ -140,20 +140,6 @@ dependencies:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '3.4'
143
- - !ruby/object:Gem::Dependency
144
- name: filewatcher
145
- requirement: !ruby/object:Gem::Requirement
146
- requirements:
147
- - - "~>"
148
- - !ruby/object:Gem::Version
149
- version: 1.1.1
150
- type: :runtime
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - "~>"
155
- - !ruby/object:Gem::Version
156
- version: 1.1.1
157
143
  - !ruby/object:Gem::Dependency
158
144
  name: zeitwerk
159
145
  requirement: !ruby/object:Gem::Requirement
@@ -267,33 +253,33 @@ dependencies:
267
253
  - !ruby/object:Gem::Version
268
254
  version: '3.0'
269
255
  - !ruby/object:Gem::Dependency
270
- name: gem-release
256
+ name: shotgun
271
257
  requirement: !ruby/object:Gem::Requirement
272
258
  requirements:
273
259
  - - "~>"
274
260
  - !ruby/object:Gem::Version
275
- version: '2.0'
261
+ version: '0.9'
276
262
  type: :development
277
263
  prerelease: false
278
264
  version_requirements: !ruby/object:Gem::Requirement
279
265
  requirements:
280
266
  - - "~>"
281
267
  - !ruby/object:Gem::Version
282
- version: '2.0'
268
+ version: '0.9'
283
269
  - !ruby/object:Gem::Dependency
284
- name: shotgun
270
+ name: timecop
285
271
  requirement: !ruby/object:Gem::Requirement
286
272
  requirements:
287
273
  - - "~>"
288
274
  - !ruby/object:Gem::Version
289
- version: '0.9'
275
+ version: 0.9.4
290
276
  type: :development
291
277
  prerelease: false
292
278
  version_requirements: !ruby/object:Gem::Requirement
293
279
  requirements:
294
280
  - - "~>"
295
281
  - !ruby/object:Gem::Version
296
- version: '0.9'
282
+ version: 0.9.4
297
283
  description:
298
284
  email:
299
285
  - 'rx@russelledens.net
@@ -359,7 +345,6 @@ files:
359
345
  - app/demo/components/selects.pom
360
346
  - app/demo/components/sliders.pom
361
347
  - app/demo/components/snackbar.pom
362
- - app/demo/components/snackbar_attached.pom
363
348
  - app/demo/components/steppers.pom
364
349
  - app/demo/components/tab_bars.pom
365
350
  - app/demo/components/tables.pom
@@ -598,14 +583,17 @@ files:
598
583
  - lib/coprl/presenters/helpers/rails.rb
599
584
  - lib/coprl/presenters/helpers/rails/currency.rb
600
585
  - lib/coprl/presenters/helpers/rails/model_table.rb
586
+ - lib/coprl/presenters/helpers/rails/routes.rb
601
587
  - lib/coprl/presenters/helpers/redact.rb
602
588
  - lib/coprl/presenters/helpers/route.rb
603
589
  - lib/coprl/presenters/helpers/time.rb
604
590
  - lib/coprl/presenters/namespace.rb
605
591
  - lib/coprl/presenters/pluggable.rb
606
592
  - lib/coprl/presenters/plugins.rb
593
+ - lib/coprl/presenters/rails/concerns/coprl_partial.rb
607
594
  - lib/coprl/presenters/rails/engine.rb
608
595
  - lib/coprl/presenters/rails/railtie.rb
596
+ - lib/coprl/presenters/rails/reloader.rb
609
597
  - lib/coprl/presenters/registry.rb
610
598
  - lib/coprl/presenters/router.rb
611
599
  - lib/coprl/presenters/settings.rb
@@ -635,6 +623,7 @@ files:
635
623
  - lib/coprl/presenters/web_client/helpers/rails/partials.rb
636
624
  - lib/coprl/presenters/web_client/helpers/rails/raw.rb
637
625
  - lib/coprl/presenters/web_client/helpers/rails/safe_markdown.rb
626
+ - lib/coprl/presenters/web_client/helpers/rails/template_helper.rb
638
627
  - lib/coprl/presenters/web_client/helpers/render_component.rb
639
628
  - lib/coprl/presenters/web_client/helpers/shared.rb
640
629
  - lib/coprl/presenters/web_client/helpers/sinatra.rb
@@ -643,6 +632,7 @@ files:
643
632
  - lib/coprl/presenters/web_client/helpers/sinatra/partials.rb
644
633
  - lib/coprl/presenters/web_client/helpers/sinatra/raw.rb
645
634
  - lib/coprl/presenters/web_client/helpers/sinatra/safe_markdown.rb
635
+ - lib/coprl/presenters/web_client/helpers/sinatra/template_helper.rb
646
636
  - lib/coprl/presenters/web_client/helpers/snake_to_camel.rb
647
637
  - lib/coprl/presenters/web_client/helpers/transform_hash.rb
648
638
  - lib/coprl/presenters/web_client/helpers/unique_id.rb
@@ -684,6 +674,7 @@ files:
684
674
  - rails-engine/app/views/layouts/coprl.html.erb
685
675
  - rails-engine/config.ru
686
676
  - rails-engine/config/initializers/presenters.rb
677
+ - rails-engine/config/initializers/routes.rb
687
678
  - rails-engine/config/initializers/session.rb
688
679
  - rails-engine/config/routes.rb
689
680
  - scripts/build.sh
@@ -815,9 +806,8 @@ files:
815
806
  - views/mdc/body/_footer.erb
816
807
  - views/mdc/body/_header.erb
817
808
  - views/mdc/body/_modal-drawer.erb
818
- - views/mdc/body/_postamble.erb
819
- - views/mdc/body/_preamble.erb
820
809
  - views/mdc/body/_snackbar.erb
810
+ - views/mdc/body/_wrapper.erb
821
811
  - views/mdc/body/drawer/_divider.erb
822
812
  - views/mdc/body/drawer/_item.erb
823
813
  - views/mdc/body/drawer/_label.erb
@@ -949,7 +939,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
949
939
  - !ruby/object:Gem::Version
950
940
  version: 1.3.1
951
941
  requirements: []
952
- rubygems_version: 3.1.4
942
+ rubygems_version: 3.1.6
953
943
  signing_key:
954
944
  specification_version: 4
955
945
  summary: COmmon PResenter Language - A Ruby gem for joyfully writing modern user interfaces
@@ -1,6 +0,0 @@
1
-
2
- Coprl::Presenters.define(:snackbar_attached) do
3
- title 'In Attached'
4
- body 'This can be done in an attached presenter as well'
5
- snackbar 'Attached Snackbar Displayed!'
6
- end
@@ -1,17 +0,0 @@
1
- <%
2
- drawer = pom.drawer
3
- footer = pom.footer
4
- %>
5
- </div>
6
- </div>
7
- <% if drawer %>
8
- </div>
9
- </div>
10
- </div>
11
- <% end %>
12
-
13
- <%= partial "body/snackbar" %>
14
- <% if footer %>
15
- <%= partial "body/footer", :locals => {:footer => footer} %>
16
- <% end %>
17
- </div>