merb_app_config 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'merb-core'
5
5
  require 'merb-core/tasks/merb'
6
6
 
7
7
  GEM_NAME = "merb_app_config"
8
- GEM_VERSION = "1.0.6"
8
+ GEM_VERSION = "1.0.7"
9
9
  AUTHOR = "Jacques Crocker"
10
10
  EMAIL = "merbjedi@gmail.com"
11
11
  HOMEPAGE = "http://www.merbjedi.com/"
@@ -1,7 +1,6 @@
1
1
  require 'ostruct'
2
2
  require 'yaml'
3
3
  require 'erb'
4
- require 'deep_merge'
5
4
 
6
5
  module ApplicationConfig
7
6
  # == Summary
@@ -129,5 +128,34 @@ module ApplicationConfig
129
128
  return new_config.uniq
130
129
  end
131
130
 
131
+ # Cycles through the array of single element hashes
132
+ # and deep merges any duplicates it finds
133
+ #
134
+ # This is needed so you can define stylesheet keys
135
+ # in multiple config files
136
+ def self.merge_assets(list)
137
+ assets = Array(list).map do |i|
138
+ if i.is_a?(OpenStruct)
139
+ i.marshal_dump
140
+ else
141
+ i
142
+ end
143
+ end
144
+
145
+ # filter out the duplicate single hash keys
146
+ hash_keys = assets.select{|i| i.is_a?(Hash) and i.keys.size == 1}.group_by{|i| i.keys[0]}
147
+ hash_keys.each do |key, value|
148
+ if Array(value).size > 1
149
+ merged = value.inject({}){|merged, v| DeepMerge.deep_merge!(v,merged)}
150
+ value[0].replace(merged)
151
+ value[1..-1].each do |v|
152
+ v.clear
153
+ end
154
+ end
155
+ end
156
+
157
+ assets.select{|i| !i.blank? }
158
+ end
159
+
132
160
  end
133
161
  end
@@ -4,11 +4,8 @@ module ApplicationConfig
4
4
  html = ""
5
5
  only = [options.delete(:only)].flatten.compact.map{|i| i.to_s}
6
6
  if defined?(AppConfig) and AppConfig.javascripts
7
- AppConfig.javascripts.each do |javascript|
8
- if javascript.is_a?(OpenStruct)
9
- javascript = javascript.marshal_dump
10
- end
11
-
7
+
8
+ ConfigBuilder.merge_assets(AppConfig.javascripts).each do |javascript|
12
9
  if javascript.is_a? Hash
13
10
  javascript.each do |key, val|
14
11
  next unless only.empty? || only.include?(key.to_s)
@@ -43,11 +40,7 @@ module ApplicationConfig
43
40
  html = ""
44
41
  only = [options.delete(:only)].flatten.compact.map{|i| i.to_s}
45
42
  if defined?(AppConfig) and AppConfig.stylesheets
46
- AppConfig.stylesheets.each do |stylesheet|
47
- if stylesheet.is_a?(OpenStruct)
48
- stylesheet = stylesheet.marshal_dump
49
- end
50
-
43
+ ConfigBuilder.merge_assets(AppConfig.stylesheets).each do |stylesheet|
51
44
  if stylesheet.is_a? Hash
52
45
  stylesheet.each do |key, val|
53
46
  next unless only.empty? || only.include?(key.to_s)
@@ -1,3 +1,4 @@
1
+ require 'application_config/deep_merge' unless defined?(DeepMerge)
1
2
  require 'application_config/config_builder'
2
3
  require 'application_config/view_helpers'
3
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb_app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacques Crocker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-30 00:00:00 -07:00
12
+ date: 2009-07-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency