refinerycms-i18n 0.9.9.14 → 0.9.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/gemspec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- version = '0.9.9.14'
2
+ version = '0.9.9.15'
3
3
  raise "Could not get version so gemspec can not be built" if version.nil?
4
4
  files = Dir.glob("**/*").flatten.reject do |file|
5
5
  file =~ /\.gem(spec)?$/
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.authors = %w(Resolve\\ Digital)
18
18
  s.require_paths = %w(lib)
19
19
 
20
- s.add_dependency 'refinerycms-core', '>= 0.9.9.8'
20
+ s.add_dependency 'refinerycms-core', '>= 0.9.9.10'
21
21
  s.add_dependency 'routing-filter', '>= 0.2.3'
22
22
 
23
23
  s.files = [
@@ -1,15 +1,21 @@
1
+ require "FileUtils" unless defined?(FileUtils)
2
+
1
3
  module SimplesIdeias
2
4
  module I18n
3
5
  extend self
4
6
 
7
+ require File.expand_path("../i18n-js/railtie", __FILE__) if Rails.version >= "3.0"
8
+
5
9
  # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
6
10
  MERGER = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2 }
7
11
 
8
- # Set configuration file path
9
- CONFIG_FILE = Rails.root.join("config/i18n-js.yml")
12
+ def config_file
13
+ Rails.root.join('config', 'i18n-js.yml')
14
+ end
10
15
 
11
- # Set i18n.js output path
12
- JAVASCRIPT_FILE = Rails.root.join("public/javascripts/i18n.js")
16
+ def javascript_file
17
+ Rails.root.join('public', 'javascripts', 'i18n.js')
18
+ end
13
19
 
14
20
  # Export translations to JavaScript, considering settings
15
21
  # from configuration file
@@ -33,26 +39,32 @@ module SimplesIdeias
33
39
  # Load configuration file for partial exporting and
34
40
  # custom output directory
35
41
  def config
36
- HashWithIndifferentAccess.new YAML.load_file(CONFIG_FILE)
42
+ yaml = HashWithIndifferentAccess.new
43
+
44
+ [config_file].flatten.each do |config|
45
+ yaml.deep_merge!(YAML.load_file(config))
46
+ end
47
+
48
+ yaml
37
49
  end
38
50
 
39
51
  # Check if configuration file exist
40
52
  def config?
41
- File.file? CONFIG_FILE
53
+ [config_file].flatten.any?{|f| File.file?(f.to_s) }
42
54
  end
43
55
 
44
56
  # Copy configuration and JavaScript library files to
45
- # <tt>SimplesIdeias::I18n::CONFIG_FILE</tt> and <tt>public/i18n.js</tt>.
57
+ # <tt>config/i18n-js.yml</tt> and <tt>public/javascripts/i18n.js</tt>.
46
58
  def setup!
47
- FileUtils.cp File.dirname(__FILE__) + "/i18n.js", JAVASCRIPT_FILE
48
- FileUtils.cp(File.dirname(__FILE__) + "/i18n-js.yml", CONFIG_FILE) unless config?
59
+ FileUtils.cp File.dirname(__FILE__) + "/../source/i18n.js", javascript_file
60
+ FileUtils.cp(File.dirname(__FILE__) + "/../source/i18n-js.yml", config_file) unless config?
49
61
  end
50
62
 
51
63
  # Retrieve an updated JavaScript library from Github.
52
64
  def update!
53
65
  require "open-uri"
54
66
  contents = open("http://github.com/fnando/i18n-js/raw/master/lib/i18n.js").read
55
- File.open(JAVASCRIPT_FILE, "w+") {|f| f << contents}
67
+ File.open(javascript_file, "w+") {|f| f << contents}
56
68
  end
57
69
 
58
70
  # Convert translations to JSON string and save file.
@@ -63,7 +75,7 @@ module SimplesIdeias
63
75
  File.open(file, "w+") do |f|
64
76
  f << %(var I18n = I18n || {};\n)
65
77
  f << %(I18n.translations = );
66
- f << sorted_hash(translations).to_json
78
+ f << translations.to_json
67
79
  f << %(;)
68
80
  end
69
81
  end
@@ -112,21 +124,5 @@ module SimplesIdeias
112
124
  def deep_merge!(target, hash) # :nodoc:
113
125
  target.merge!(hash, &MERGER)
114
126
  end
115
-
116
- # Taken from http://seb.box.re/2010/1/15/deep-hash-ordering-with-ruby-1-8/
117
- def sorted_hash(object, deep = false) # :nodoc:
118
- if object.is_a?(Hash)
119
- res = returning(ActiveSupport::OrderedHash.new) do |map|
120
- object.each {|k, v| map[k] = deep ? sorted_hash(v, deep) : v }
121
- end
122
- return res.class[res.sort {|a, b| a[0].to_s <=> b[0].to_s } ]
123
- elsif deep && object.is_a?(Array)
124
- array = Array.new
125
- object.each_with_index {|v, i| array[i] = sorted_hash(v, deep) }
126
- return array
127
- else
128
- return object
129
- end
130
- end
131
127
  end
132
- end
128
+ end
@@ -1,4 +1,4 @@
1
1
  # Find more details about this configuration file at http://github.com/fnando/i18n-js
2
2
  translations:
3
3
  - file: "public/javascripts/translations.js"
4
- only: "*"
4
+ only: "*.js.*"
@@ -0,0 +1,9 @@
1
+ module SimplesIdeias
2
+ module I18n
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load File.dirname(__FILE__) + "../../../tasks/i18n-js_tasks.rake"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module SimplesIdeias
2
+ module I18n
3
+ module Version
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ PATCH = 1
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
+ end
9
+ end
10
+ end
data/lib/refinery/i18n.rb CHANGED
@@ -21,6 +21,10 @@ module Refinery
21
21
 
22
22
  config.to_prepare do
23
23
  ::ApplicationController.class_eval do
24
+ before_filter lambda {|c|
25
+ ::SimplesIdeias::I18n.export! if Rails.env.development?
26
+ }
27
+
24
28
  def default_url_options(options={})
25
29
  ::Refinery::I18n.enabled? ? { :locale => ::I18n.locale } : {}
26
30
  end
@@ -13,4 +13,4 @@ namespace :i18n do
13
13
  task :update => :environment do
14
14
  SimplesIdeias::I18n.update!
15
15
  end
16
- end
16
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: refinerycms-i18n
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.9.14
5
+ version: 0.9.9.15
6
6
  platform: ruby
7
7
  authors:
8
8
  - Resolve Digital
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-15 00:00:00 +13:00
13
+ date: 2011-03-24 00:00:00 +13:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 0.9.9.8
24
+ version: 0.9.9.10
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -119,6 +119,8 @@ files:
119
119
  - i18n-js-readme.rdoc
120
120
  - lib/gemspec.rb
121
121
  - lib/refinery/i18n-filter.rb
122
+ - lib/refinery/i18n-js/railtie.rb
123
+ - lib/refinery/i18n-js/version.rb
122
124
  - lib/refinery/i18n-js.rb
123
125
  - lib/refinery/i18n-js.yml
124
126
  - lib/refinery/i18n.js