merb-plugins-app-config 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +12 -3
- data/Rakefile +1 -1
- data/lib/application_config/view_helpers.rb +72 -12
- data/lib/merb-plugins-app-config.rb +8 -3
- data/spec/test_configs/ordered_hash_array.yml +18 -0
- metadata +2 -1
data/README
CHANGED
@@ -36,20 +36,29 @@ You can also define your javascripts and stylesheets using AppConfig
|
|
36
36
|
Merb.root/config/javascripts.yml
|
37
37
|
Merb.root/config/stylesheets.yml
|
38
38
|
|
39
|
-
prototype:
|
39
|
+
- prototype-bundle:
|
40
40
|
- prototype
|
41
41
|
- scriptaculous
|
42
42
|
|
43
|
-
jquery:
|
43
|
+
- jquery-bundle:
|
44
44
|
- jquery
|
45
45
|
- jquery.ui/tabs
|
46
46
|
|
47
|
-
components:
|
47
|
+
- components-bundle:
|
48
48
|
- components/blah
|
49
49
|
- components/blah2
|
50
50
|
|
51
51
|
This will include all the javasciprt files listed when running the helper "javascripts", and on prod, it will bundle them up by key (prototype-bundle.js, jquery-bundle.js, components-bundle.js)
|
52
52
|
|
53
|
+
If you want to see something really awesome, try this:
|
54
|
+
- jquery-bundle:
|
55
|
+
- jquery
|
56
|
+
- jquery.ui/*
|
57
|
+
- jquery.plugins/*
|
58
|
+
|
59
|
+
On the first request this will grab *ALL* the files from these folders (using Dir[path]),
|
60
|
+
and bundle them on. On subsequent requests, it will use the bundle directly
|
61
|
+
|
53
62
|
In your application layout, just include the calls to
|
54
63
|
<%= stylesheets %>
|
55
64
|
<%= javascripts %>
|
data/Rakefile
CHANGED
@@ -1,27 +1,87 @@
|
|
1
1
|
module ApplicationConfig
|
2
2
|
module ViewHelpers
|
3
|
+
|
4
|
+
# Collects all javascripts found in the app_configs and outputs them as script tags
|
3
5
|
def javascripts
|
4
|
-
|
6
|
+
asset_list = []
|
5
7
|
if AppConfig.javascripts
|
6
|
-
|
8
|
+
asset_list << AppConfig.javascripts.to_a
|
7
9
|
end
|
8
|
-
|
9
|
-
|
10
|
+
asset_list << AppConfigJavascripts.javascripts.to_a
|
11
|
+
|
12
|
+
html = []
|
13
|
+
asset_list.flatten.compact.each do |bundle_list|
|
14
|
+
if bundle_list.is_a? String
|
15
|
+
html << js_include_tag(bundle_list)
|
16
|
+
else
|
17
|
+
bundle_list = bundle_list.marshal_dump if bundle_list.is_a? OpenStruct
|
18
|
+
bundle_list.each do |key, path_list|
|
19
|
+
path_list = [path_list].flatten
|
20
|
+
|
21
|
+
scripts = []
|
22
|
+
path_list.each do |path|
|
23
|
+
if path.to_s.include?("*")
|
24
|
+
if Merb::Assets::JavascriptAssetBundler.cached_bundle?(key.to_sym)
|
25
|
+
scripts << key.to_s
|
26
|
+
else
|
27
|
+
Dir["#{Merb.root}/public/javascripts/#{path}"].each do |item|
|
28
|
+
scripts << item.gsub("#{Merb.root}/public/javascripts/", "")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
scripts << path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
scripts << {:bundle => key.to_sym}
|
36
|
+
html << js_include_tag(*scripts)
|
37
|
+
end
|
38
|
+
end
|
10
39
|
end
|
11
|
-
|
40
|
+
|
41
|
+
html << include_required_js
|
42
|
+
html.join("\n")
|
12
43
|
end
|
13
|
-
|
44
|
+
|
45
|
+
# Collects all stylesheets found in the app_configs and outputs them as link tags
|
14
46
|
def stylesheets
|
15
|
-
|
47
|
+
asset_list = []
|
16
48
|
if AppConfig.stylesheets
|
17
|
-
|
49
|
+
asset_list << AppConfig.stylesheets.to_a
|
18
50
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
51
|
+
asset_list << AppConfigStylesheets.stylesheets.to_a
|
52
|
+
|
53
|
+
html = []
|
54
|
+
asset_list.flatten.compact.each do |bundle_list|
|
55
|
+
if bundle_list.is_a? String
|
56
|
+
html << css_include_tag(bundle_list)
|
57
|
+
else
|
58
|
+
bundle_list = bundle_list.marshal_dump if bundle_list.is_a? OpenStruct
|
59
|
+
bundle_list.each do |key, path_list|
|
60
|
+
path_list = [path_list].flatten
|
61
|
+
|
62
|
+
scripts = []
|
63
|
+
path_list.each do |path|
|
64
|
+
if path.to_s.include?("*")
|
65
|
+
if Merb::Assets::StylesheetAssetBundler.cached_bundle?(key.to_sym)
|
66
|
+
scripts << key.to_s
|
67
|
+
else
|
68
|
+
Dir["#{Merb.root}/public/stylesheets/#{path}"].each do |item|
|
69
|
+
scripts << item.gsub("#{Merb.root}/public/stylesheets/", "")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
else
|
73
|
+
scripts << path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
scripts << {:bundle => key.to_sym}
|
77
|
+
html << css_include_tag(*scripts)
|
78
|
+
end
|
79
|
+
end
|
22
80
|
end
|
23
81
|
|
24
|
-
include_required_css
|
82
|
+
html << include_required_css
|
83
|
+
html.join("\n")
|
25
84
|
end
|
85
|
+
|
26
86
|
end
|
27
87
|
end
|
@@ -22,14 +22,18 @@ if defined?(Merb::Plugins)
|
|
22
22
|
AppConfigStylesheets.reload!
|
23
23
|
else
|
24
24
|
::AppConfigStylesheets = ApplicationConfig::ConfigBuilder.load_files("#{Merb.root}/config/stylesheets.yml",
|
25
|
-
"#{Merb.root}/config/app_config/stylesheets.yml"
|
25
|
+
"#{Merb.root}/config/app_config/stylesheets.yml",
|
26
|
+
"#{Merb.root}/config/assets.yml",
|
27
|
+
"#{Merb.root}/config/app_config/assets.yml")
|
26
28
|
end
|
27
29
|
|
28
30
|
if defined?(::AppConfigJavascripts)
|
29
31
|
AppConfigJavascripts.reload!
|
30
32
|
else
|
31
33
|
::AppConfigJavascripts = ApplicationConfig::ConfigBuilder.load_files("#{Merb.root}/config/javascripts.yml",
|
32
|
-
"#{Merb.root}/config/app_config/javascripts.yml"
|
34
|
+
"#{Merb.root}/config/app_config/javascripts.yml",
|
35
|
+
"#{Merb.root}/config/assets.yml",
|
36
|
+
"#{Merb.root}/config/app_config/assets.yml")
|
33
37
|
end
|
34
38
|
|
35
39
|
Merb::Controller.send(:include, ApplicationConfig::ViewHelpers)
|
@@ -38,7 +42,8 @@ if defined?(Merb::Plugins)
|
|
38
42
|
|
39
43
|
Merb::BootLoader.after_app_loads do
|
40
44
|
if Merb::Plugins.config[:app_config][:auto_reload]
|
41
|
-
Merb.logger.info "Auto reloading AppConfig on *every request*.
|
45
|
+
Merb.logger.info "[AppConfig] Auto reloading AppConfig on *every request*."
|
46
|
+
Merb.logger.info "[AppConfig] Set via Merb::Plugins.config[:app_config][:auto_reload]"
|
42
47
|
Merb::Controller.before do
|
43
48
|
AppConfig.reload!
|
44
49
|
if Merb::Plugins.config[:app_config][:include_viewhelpers]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-plugins-app-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.5"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacques Crocker
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- spec/test_configs/development.yml
|
58
58
|
- spec/test_configs/empty1.yml
|
59
59
|
- spec/test_configs/empty2.yml
|
60
|
+
- spec/test_configs/ordered_hash_array.yml
|
60
61
|
has_rdoc: true
|
61
62
|
homepage: http://www.merbjedi.com/
|
62
63
|
post_install_message:
|