frails 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/frails/helper.rb +9 -16
- data/lib/frails/monkey/action_view/abstract_renderer.rb +0 -2
- data/lib/frails/monkey/action_view/partial_renderer.rb +7 -1
- data/lib/frails/monkey/action_view/template_renderer.rb +8 -1
- data/lib/frails/railtie.rb +1 -9
- data/lib/frails/side_load_assets.rb +8 -5
- data/lib/frails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a5dc3c71ad5adadae28c1dd72b8b2dbff630c6b51d93084b3dce0b6902eed42
|
4
|
+
data.tar.gz: 580fe686a4e0e93779571144fbc3ccd9d55398cb1a67683310068310903954bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28ee475ad7e401f72434510f8ed2fce9d05ecf57640ab13f7655e897b3995d3f422d9dfdec946f763c88cf7ce0282c531d280da23c641040ea39708923618ece
|
7
|
+
data.tar.gz: a3142865ffd21446af2f877c30938fe6b91ea3eedf550d6dc585478ed6c87f15fa7b7fa7e3676f9592ea68cd8580529c4af35cd07e61976d62e557a8298d22a6
|
data/README.md
CHANGED
@@ -100,11 +100,12 @@ image_pack_tag 'logo.png'
|
|
100
100
|
Frails has the ability to automatically include your Javascript and CSS based on the current layout
|
101
101
|
and/or view. It even supports side loading partials.
|
102
102
|
|
103
|
-
Just
|
103
|
+
Just set the `side_load_assets` class variable to your `ApplicationController`, or indeed to any
|
104
|
+
controller.
|
104
105
|
|
105
106
|
```ruby
|
106
107
|
class ApplicationController < ActionController::Base
|
107
|
-
side_load_assets
|
108
|
+
self.side_load_assets = true
|
108
109
|
end
|
109
110
|
```
|
110
111
|
|
data/lib/frails/helper.rb
CHANGED
@@ -2,31 +2,24 @@
|
|
2
2
|
|
3
3
|
module Frails::Helper
|
4
4
|
def render(options = {}, locals = {}, &block)
|
5
|
+
sload_assets = respond_to?(:side_load_assets?) ? side_load_assets? : false
|
6
|
+
|
5
7
|
case options
|
6
8
|
when Hash
|
7
|
-
|
8
|
-
|
9
|
-
if block_given?
|
10
|
-
# MONKEY PATCH! simply renders the component with the given block.
|
11
|
-
return view_renderer.render_component(self, options, &block) if options.key?(:component)
|
12
|
-
|
13
|
-
view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
|
14
|
-
else
|
15
|
-
view_renderer.render(self, options)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
else
|
19
|
-
if block_given?
|
20
|
-
# MONKEY PATCH! simply renders the component with the given block.
|
21
|
-
return view_renderer.render_component(self, options, &block) if options.key?(:component)
|
9
|
+
in_rendering_context(options) do
|
10
|
+
options[:side_load_assets] = sload_assets
|
22
11
|
|
12
|
+
return view_renderer.render_component(self, options, &block) if options.key?(:component)
|
13
|
+
|
14
|
+
if block_given?
|
23
15
|
view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
|
24
16
|
else
|
25
17
|
view_renderer.render(self, options)
|
26
18
|
end
|
27
19
|
end
|
28
20
|
else
|
29
|
-
view_renderer.render_partial(self,
|
21
|
+
view_renderer.render_partial(self, side_load_assets: sload_assets, partial: options,
|
22
|
+
locals: locals, &block)
|
30
23
|
end
|
31
24
|
end
|
32
25
|
|
@@ -5,8 +5,6 @@ module Frails
|
|
5
5
|
module ActionView
|
6
6
|
module AbstractRenderer
|
7
7
|
def side_load_assets(view, tpl)
|
8
|
-
return unless view.controller._side_load_assets?
|
9
|
-
|
10
8
|
path = tpl.short_identifier.delete_prefix('app/').delete_suffix('.html.erb')
|
11
9
|
|
12
10
|
instrument :side_loaded_assets, identifier: tpl.identifier, asset_types: [] do |payload|
|
@@ -6,7 +6,13 @@ module Frails
|
|
6
6
|
module PartialRenderer
|
7
7
|
def render_partial(view, template)
|
8
8
|
# Side load partial assets - if any.
|
9
|
-
@asset_path = side_load_assets(view, template)
|
9
|
+
@asset_path = @side_load_assets && side_load_assets(view, template)
|
10
|
+
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup(context, options, as, block)
|
15
|
+
@side_load_assets = options.key?(:side_load_assets) ? options[:side_load_assets] : false
|
10
16
|
|
11
17
|
super
|
12
18
|
end
|
@@ -4,8 +4,15 @@ module Frails
|
|
4
4
|
module Monkey
|
5
5
|
module ActionView
|
6
6
|
module TemplateRenderer
|
7
|
+
def render(context, options)
|
8
|
+
# See Frails::SideLoadAssets
|
9
|
+
@side_load_assets = options.key?(:side_load_assets) ? options[:side_load_assets] : false
|
10
|
+
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
7
14
|
def render_template(view, template, layout_name, locals)
|
8
|
-
return super if template.type != :html
|
15
|
+
return super if !@side_load_assets || template.type != :html
|
9
16
|
|
10
17
|
# Side load layout assets - if any.
|
11
18
|
if layout_name
|
data/lib/frails/railtie.rb
CHANGED
@@ -9,7 +9,7 @@ class Frails::Engine < ::Rails::Engine
|
|
9
9
|
app.middleware.insert_before 0, Frails::DevServerProxy, ssl_verify_none: true
|
10
10
|
end
|
11
11
|
|
12
|
-
initializer 'frails
|
12
|
+
initializer 'frails' do
|
13
13
|
ActiveSupport.on_load :action_controller do
|
14
14
|
require 'frails/side_load_assets'
|
15
15
|
|
@@ -32,15 +32,7 @@ class Frails::Engine < ::Rails::Engine
|
|
32
32
|
ActionView::TemplateRenderer.send :prepend, Frails::Monkey::ActionView::TemplateRenderer
|
33
33
|
ActionView::PartialRenderer.send :prepend, Frails::Monkey::ActionView::PartialRenderer
|
34
34
|
ActionView::Renderer.send :prepend, Frails::Monkey::ActionView::Renderer
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
initializer 'frails.helper' do
|
39
|
-
ActiveSupport.on_load :action_controller do
|
40
|
-
ActionController::Base.helper Frails::Helper
|
41
|
-
end
|
42
35
|
|
43
|
-
ActiveSupport.on_load :action_view do
|
44
36
|
include Frails::Helper
|
45
37
|
end
|
46
38
|
end
|
@@ -4,12 +4,15 @@ module Frails::SideLoadAssets
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
class_attribute :
|
7
|
+
class_attribute :side_load_assets, default: false
|
8
|
+
helper_method :side_load_assets?
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
# Add _side_load_assets flag to the options hash, which will be available in TemplateRenderer,
|
12
|
+
# allowing us control if views/layouts are side loaded.
|
13
|
+
def _normalize_options(options)
|
14
|
+
super
|
15
|
+
options[:side_load_assets] = side_load_assets
|
16
|
+
options
|
14
17
|
end
|
15
18
|
end
|
data/lib/frails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|