Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/coprl/presenters/dsl/components/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def context

alias params context


def yield_block
return @_yield_block_ if @_yield_block_
@parent.send(:yield_block)
Expand Down
4 changes: 2 additions & 2 deletions lib/coprl/presenters/dsl/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def build
self
end

def expand(router: , context:{}, &block)
presenter = UserInterface.new(router: router, context: context, name: @name, namespace: @namespace, &@block)
def expand(router: , context:{}, plugins: [], &block)
presenter = UserInterface.new(router: router, context: context, plugins: plugins, name: @name, namespace: @namespace, &@block)
yield(presenter) if block
presenter.expand_instance
end
Expand Down
4 changes: 2 additions & 2 deletions lib/coprl/presenters/dsl/user_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UserInterface
private :context, :router, :namespace
alias params context

def initialize(context:, parent: nil, router: nil, name: nil, namespace: [], &block)
def initialize(context:, parent: nil, router: nil, name: nil, plugins: [], namespace: [], &block)
@parent = parent
@router = router || @parent&.send(:router)
@context = context || {}
Expand All @@ -36,7 +36,7 @@ def initialize(context:, parent: nil, router: nil, name: nil, namespace: [], &bl
@footer = nil
@name = name
@namespace = namespace
@plugins = []
@plugins = plugins || []
@csrf_meta_tags = authenticity_token_meta_tags(@context.fetch(:session, nil))
add_global_helpers
initialize_plugins
Expand Down
32 changes: 32 additions & 0 deletions lib/coprl/presenters/rails/concerns/coprl_view_paths.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Coprl
module Presenters
module Rails
module Concerns
module CoprlViewPaths
extend ActiveSupport::Concern

included do
before_action :set_view_path
end

module ClassMethods
def presenter_plugin(*plugins)
@plugins = Array(plugins)
end

def plugins
@plugins || []
end
end

def set_view_path
paths = Coprl::Presenters::WebClient::PluginViewsPath.new(pom: nil, plugins: self.class.plugins).render
paths.each do |path|
prepend_view_path path
end
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions lib/coprl/presenters/rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Engine < ::Rails::Engine
# TODO: should rename these since they are common names that are likely going to collide
app.middleware.use ::ActionDispatch::Static, File.join(root, '..', 'public')
end

ActiveSupport.on_load(:action_controller) do
include Concerns::CoprlViewPaths
end

end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/coprl/presenters/web_client/plugin_views_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ class PluginViewsPath
extend Pluggable
include_plugins(:WebClientComponents)

def initialize(pom:)
def initialize(pom: nil, plugins: nil)
@pom = pom
@plugins = plugins || []
initialize_plugins
end

def render
results = []
((@plugins||[]) + Coprl::Presenters::Settings.config.presenters.plugins).each do |plugin|
(@plugins + Coprl::Presenters::Settings.config.presenters.plugins).each do |plugin|
view_dir_method = :"view_dir_#{plugin}"
results << send(view_dir_method,
@pom) if respond_to?(view_dir_method)
results << send(view_dir_method, @pom) if respond_to?(view_dir_method)
end
results
end

private

def initialize_plugins
@plugins = @pom.send(:plugins)
@plugins << @pom.send(:plugins) if @pom
self.class.include_plugins(:WebClientComponents, plugins: @plugins)
end
end
Expand Down
3 changes: 2 additions & 1 deletion rails-engine/config/initializers/presenters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def presenter_template(source)
presenter = Coprl::Presenters::App[presenter_name].call
context = params.dup.to_unsafe_hash
router = Coprl::Presenters::WebClient::Router.new(base_url: request.base_url)
@pom = presenter.expand(router: router, context: context)
plugins = self.controller.class.plugins
@pom = presenter.expand(router: router, context: context, plugins: plugins)
end
#{source}
end
Expand Down