coprl 3.0.0.beta.6 → 3.0.0.beta.7

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: 7d5886d0ba61fa0e7a694b0463ef695007c3c64e3c601344b96e9d6cdcd74e14
4
- data.tar.gz: c6acd24734fb08dfa86e416cefecf8936e816ee390fe2eb150be085c6e0b7552
3
+ metadata.gz: f1e42760026c49cf31fd1e7b4828e1f35d425c4bd9210431854e19dd6791b0dc
4
+ data.tar.gz: fc418edb85902d702985446356561526ba54f04d36c96eb97871d9479a96cd1f
5
5
  SHA512:
6
- metadata.gz: e5b77286cfd3b3ee1df288e8a9394dbc16d3bae8ccb148dec73b90af4021c653b4266ca5f8cdc404268d7d6e118b5dd1f9a13fe34b1db4bad8e3aa2b7ba9159a
7
- data.tar.gz: 0b8b5ce497af6367a3c48b1f82dae262441ef125e9908cd29c37d08e8f371cfe2e3c187b851fdc497cc7f7573d84a13d480569d0967d1e26a904157a1556516c
6
+ metadata.gz: 2f214706da76cc52329f24f92bdc16c83b54ef6550ca59ccf996f4baf665c00db04fe4b3eae5125ebd2cf7dacfa0fb3853e66d866e8e99981e315441ae99fab8
7
+ data.tar.gz: d36d7a083fd7d0d1212db2271a3c6669cb84f398ca02b7d64e7ed349c203456c0a3aecd71c727cd241f666265a527ade93b312c7203eb63f5048bebd49074741
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # [3.0.0-beta.7](https://github.com/rx/presenters/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-07-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Rails routes automatically made available as helpers ([#322](https://github.com/rx/presenters/issues/322)) ([abb0031](https://github.com/rx/presenters/commit/abb00311940fda8741459f8aafe29cd7bf074b88))
7
+ * 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))
8
+
9
+
10
+ ### Features
11
+
12
+ * 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))
13
+
1
14
  # [3.0.0-beta.6](https://github.com/rx/presenters/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-06-23)
2
15
 
3
16
 
data/Gemfile.lock CHANGED
@@ -84,7 +84,6 @@ PATH
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)
@@ -111,8 +110,6 @@ GEM
111
110
  dry-core (0.6.0)
112
111
  concurrent-ruby (~> 1.0)
113
112
  dry-inflector (0.2.0)
114
- filewatcher (1.1.1)
115
- optimist (~> 3.0)
116
113
  ice_nine (0.11.2)
117
114
  json (2.3.1)
118
115
  method_source (0.9.0)
@@ -125,7 +122,6 @@ GEM
125
122
  racc (~> 1.4)
126
123
  nokogiri (1.11.7-x86_64-darwin)
127
124
  racc (~> 1.4)
128
- optimist (3.0.1)
129
125
  pry (0.11.3)
130
126
  coderay (~> 1.1.0)
131
127
  method_source (~> 0.9.0)
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'
@@ -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
@@ -6,12 +6,9 @@ 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(':', '/')
@@ -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[:request].host_with_port }
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -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.6'
4
+ VERSION = '3.0.0.beta.7'
5
5
  end
6
6
  end
7
7
  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
@@ -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
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.6
4
+ version: 3.0.0.beta.7
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-23 00:00:00.000000000 Z
11
+ date: 2021-07-09 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
@@ -597,14 +583,17 @@ files:
597
583
  - lib/coprl/presenters/helpers/rails.rb
598
584
  - lib/coprl/presenters/helpers/rails/currency.rb
599
585
  - lib/coprl/presenters/helpers/rails/model_table.rb
586
+ - lib/coprl/presenters/helpers/rails/routes.rb
600
587
  - lib/coprl/presenters/helpers/redact.rb
601
588
  - lib/coprl/presenters/helpers/route.rb
602
589
  - lib/coprl/presenters/helpers/time.rb
603
590
  - lib/coprl/presenters/namespace.rb
604
591
  - lib/coprl/presenters/pluggable.rb
605
592
  - lib/coprl/presenters/plugins.rb
593
+ - lib/coprl/presenters/rails/concerns/coprl_partial.rb
606
594
  - lib/coprl/presenters/rails/engine.rb
607
595
  - lib/coprl/presenters/rails/railtie.rb
596
+ - lib/coprl/presenters/rails/reloader.rb
608
597
  - lib/coprl/presenters/registry.rb
609
598
  - lib/coprl/presenters/router.rb
610
599
  - lib/coprl/presenters/settings.rb
@@ -685,6 +674,7 @@ files:
685
674
  - rails-engine/app/views/layouts/coprl.html.erb
686
675
  - rails-engine/config.ru
687
676
  - rails-engine/config/initializers/presenters.rb
677
+ - rails-engine/config/initializers/routes.rb
688
678
  - rails-engine/config/initializers/session.rb
689
679
  - rails-engine/config/routes.rb
690
680
  - scripts/build.sh