rake-pipeline-i18n-filters 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.yardopts +2 -0
- data/Gemfile +7 -0
- data/README.markdown +4 -0
- data/README.yard +38 -0
- data/Rakefile +19 -0
- data/lib/ext/hash.rb +23 -0
- data/lib/rake-pipeline-i18n-filters/ember_strings_filter.rb +91 -0
- data/lib/rake-pipeline-i18n-filters/filter_with_dependencies.rb +27 -0
- data/lib/rake-pipeline-i18n-filters/helpers.rb +19 -0
- data/lib/rake-pipeline-i18n-filters/i18n_js_filter.rb +54 -0
- data/lib/rake-pipeline-i18n-filters/version.rb +9 -0
- data/lib/rake-pipeline-i18n-filters.rb +17 -0
- data/rake-pipeline-i18n-filters.gemspec +19 -0
- data/spec/ember_strings_filter_spec.rb +51 -0
- data/spec/helpers_spec.rb +25 -0
- data/spec/i18n_js_filter_spec.rb +50 -0
- data/spec/spec_helper.rb +103 -0
- metadata +107 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-cfs -r spec_helper.rb
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
data/README.yard
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= Rake::Pipeline::I18n::Filters
|
2
|
+
|
3
|
+
Rake::Pipeline::I18n::Filters is a collection of filters for Rake::Pipeline
|
4
|
+
for creating pipelines to generate i18n-js and Ember.STRINGS
|
5
|
+
localization files from I18n yaml.
|
6
|
+
|
7
|
+
= Usage
|
8
|
+
|
9
|
+
In your +Assetfile+:
|
10
|
+
|
11
|
+
!!!ruby
|
12
|
+
require "rake-pipeline-i18n-filters"
|
13
|
+
|
14
|
+
input "assets"
|
15
|
+
output "public"
|
16
|
+
|
17
|
+
# Take all YAML inputs and generates JS suitable for
|
18
|
+
# use with i18n-js
|
19
|
+
output 'public/scripts'
|
20
|
+
input 'locales' do
|
21
|
+
match '**/*.yml' do
|
22
|
+
i18n_js { 'locales.js' }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Take all YAML inputs and generate JS suitable for
|
27
|
+
# use with Ember.STRINGS
|
28
|
+
output 'assets/scripts/config'
|
29
|
+
input 'locales' do
|
30
|
+
match '**/*.yml' do
|
31
|
+
ember_strings { 'locales.js' }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
= Available Filters
|
36
|
+
|
37
|
+
* {Rake::Pipeline::I18n::Filters::I18nJsFilter}: Compile yaml files to JS suitable for use by i18n-js
|
38
|
+
* {Rake::Pipeline::I18n::Filters::EmberStringFilter}: Compile YAML to JS * suitable for EmberJS.STRINGS
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "bundler/setup"
|
4
|
+
|
5
|
+
desc "run the specs"
|
6
|
+
task :spec do
|
7
|
+
sh "rspec -cfs spec"
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
11
|
+
|
12
|
+
desc "build the gem"
|
13
|
+
task :build do
|
14
|
+
system "gem build rake-pipeline-i18n-filters.gemspec"
|
15
|
+
end
|
16
|
+
desc "build and release the gem"
|
17
|
+
task :release => :build do
|
18
|
+
system "gem push activeadmin-axlsx-#{Rake::Pipeline::I18n::Filters::VERSION}.gem"
|
19
|
+
end
|
data/lib/ext/hash.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Shamelessly borrowed from active_support. Simply because I dont want
|
2
|
+
# to force the dependency.
|
3
|
+
class Hash
|
4
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
5
|
+
#
|
6
|
+
# h1 = {:x => {:y => [4,5,6]}, :z => [7,8,9]}
|
7
|
+
# h2 = {:x => {:y => [7,8,9]}, :z => "xyz"}
|
8
|
+
#
|
9
|
+
# h1.deep_merge(h2) #=> { :x => {:y => [7, 8, 9]}, :z => "xyz" }
|
10
|
+
# h2.deep_merge(h1) #=> { :x => {:y => [4, 5, 6]}, :z => [7, 8, 9] }
|
11
|
+
def deep_merge(other_hash)
|
12
|
+
dup.deep_merge!(other_hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Same as +deep_merge+, but modifies +self+.
|
16
|
+
def deep_merge!(other_hash)
|
17
|
+
other_hash.each_pair do |k,v|
|
18
|
+
tv = self[k]
|
19
|
+
self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
|
20
|
+
end
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rake-pipeline-i18n-filters/filter_with_dependencies'
|
2
|
+
|
3
|
+
module Rake::Pipeline::I18n::Filters
|
4
|
+
# A filter that compiles locale yml files into javascript
|
5
|
+
# appropriate for use by Ember#String#loc
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# !!!ruby
|
9
|
+
# Rake::Pipeline.build do
|
10
|
+
# input "config/locales", "**/*.yml"
|
11
|
+
# output "public"
|
12
|
+
#
|
13
|
+
# # Compile each .yml file under the config/locales
|
14
|
+
# # directory.
|
15
|
+
# filter Rake::Pipeline::Web::Filters::EmberI18nFilter
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
class EmberStringsFilter < Rake::Pipeline::Filter
|
19
|
+
|
20
|
+
include FilterWithDependencies
|
21
|
+
|
22
|
+
# @param [Hash] options
|
23
|
+
# A hash of options for this filter
|
24
|
+
# @option [String] :use_i18n_js
|
25
|
+
# When true, localization information will be output in a format
|
26
|
+
# suitable for i18n-js. If this option is missing data will be
|
27
|
+
# output in the format that Ember.String.loc expects.
|
28
|
+
# @note If you are using Ember.String.loc be sure to set
|
29
|
+
# Ember.STRINGS = EmberI18n['locale'];
|
30
|
+
# where 'locale' is the locale you have parsed and want to render.
|
31
|
+
# @see https://github.com/fnando/i18n-js
|
32
|
+
# @see http://docs.emberjs.com/symbols/Ember.String.html#method=.loc
|
33
|
+
# @param [Proc] block a block to use as the Filter's
|
34
|
+
# {#output_name_generator}.
|
35
|
+
def initialize(&block)
|
36
|
+
block ||= proc { |input| input.sub(/\.(yml)$/, '.js') }
|
37
|
+
super(&block)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Implement the {#generate_output} method required by
|
41
|
+
# the {Filter} API. Generates javascript from i18n yaml files
|
42
|
+
# appropriate for Ember#String#loc or i18n-js
|
43
|
+
# @param [Array<FileWrapper>] inputs an Array of
|
44
|
+
# {FileWrapper} objects representing the inputs to
|
45
|
+
# this filter.
|
46
|
+
# @param [FileWrapper] output a single {FileWrapper}
|
47
|
+
# object representing the output.
|
48
|
+
def generate_output(inputs, output)
|
49
|
+
output.write ember_i18n_output(inputs)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def external_dependencies
|
55
|
+
[ 'yaml', 'json' ]
|
56
|
+
end
|
57
|
+
|
58
|
+
def ember_i18n_output(inputs)
|
59
|
+
"EmberI18n = EmberI18n || {};#{compile_locales_for_ember_i18n(inputs)}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def compile_locales_for_ember_i18n(inputs)
|
63
|
+
output_hash = {}
|
64
|
+
inputs.map do |input|
|
65
|
+
output_hash.deep_merge! YAML.load(input.read)
|
66
|
+
end
|
67
|
+
parse_ember_i18n_locales(output_hash)
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_ember_i18n_locales(output_hash)
|
71
|
+
dotified = dotify(output_hash)
|
72
|
+
dotified.map do |locale_key, locale_value|
|
73
|
+
locale_strings = locale_value.map do |entry_key, entry_value|
|
74
|
+
"'#{entry_key}' : '#{entry_value}'"
|
75
|
+
end.join(',')
|
76
|
+
"EmberI18n['#{locale_key}'] = { #{locale_strings} };"
|
77
|
+
end.join('')
|
78
|
+
end
|
79
|
+
|
80
|
+
def dotify(source, target={}, path=nil)
|
81
|
+
prefix = "#{path}." if path
|
82
|
+
if source.is_a?(Hash)
|
83
|
+
source.each do |key, value|
|
84
|
+
dotify(value, target, "#{prefix}#{key}")
|
85
|
+
end
|
86
|
+
else
|
87
|
+
target[path.split('.')[1..-1].join('.')] = source
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rake::Pipeline::I18n::Filters
|
2
|
+
# A mixin for filters that have dependencies on external
|
3
|
+
# libraries. Include this module in the filter class and
|
4
|
+
# declare a private `external_dependencies` method that
|
5
|
+
# returns an array of strings. Each one will be passed
|
6
|
+
# to `Kernel#require` when an instance of the filter
|
7
|
+
# is created.
|
8
|
+
module FilterWithDependencies
|
9
|
+
|
10
|
+
def initialize(*args, &block)
|
11
|
+
require_dependencies!
|
12
|
+
super(*args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def require_dependencies!
|
18
|
+
external_dependencies.each do |d|
|
19
|
+
begin
|
20
|
+
require d
|
21
|
+
rescue LoadError => error
|
22
|
+
raise error, "#{self.class} requires #{d}, but it is not available."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rake::Pipeline::I18n::Filters
|
2
|
+
# Extends the Rake::Pipeline DSL to include shortcuts
|
3
|
+
# for adding filters to the pipeline.
|
4
|
+
module PipelineHelpers
|
5
|
+
# Add a new {I18nJsFilter} to the pipeline
|
6
|
+
# @see I18nJsFilter#initialize
|
7
|
+
def i18n_js(*args, &block)
|
8
|
+
filter(Rake::Pipeline::I18n::Filters::I18nJsFilter, *args, &block)
|
9
|
+
end
|
10
|
+
# Add a new {EmberStringsFilter} to the pipeline
|
11
|
+
# @see EmberStringsFilter#initialize
|
12
|
+
def ember_strings(*args, &block)
|
13
|
+
filter(Rake::Pipeline::I18n::Filters::EmberStringsFilter, *args, &block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require "rake-pipeline/dsl"
|
19
|
+
Rake::Pipeline::DSL::PipelineDSL.send(:include, Rake::Pipeline::I18n::Filters::PipelineHelpers)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rake-pipeline-i18n-filters/filter_with_dependencies'
|
2
|
+
|
3
|
+
module Rake::Pipeline::I18n::Filters
|
4
|
+
# A filter that compiles locale yml files into javascript
|
5
|
+
# appropriate for use by Ember#String#loc
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# !!!ruby
|
9
|
+
# Rake::Pipeline.build do
|
10
|
+
# input "config/locales", "**/*.yml"
|
11
|
+
# output "public"
|
12
|
+
#
|
13
|
+
# # Compile each .yml file under the config/locales
|
14
|
+
# # directory.
|
15
|
+
# filter Rake::Pipeline::I18n::Filters::I18nJSFilter
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
class I18nJsFilter < Rake::Pipeline::Filter
|
19
|
+
|
20
|
+
include FilterWithDependencies
|
21
|
+
|
22
|
+
# @see https://github.com/fnando/i18n-js
|
23
|
+
# @param [Proc] block a block to use as the Filter's
|
24
|
+
# {#output_name_generator}.
|
25
|
+
def initialize(&block)
|
26
|
+
block ||= proc { |input| input.sub(/\.(yml)$/, '.js') }
|
27
|
+
super(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Implement the {#generate_output} method required by
|
31
|
+
# the {Filter} API. Generates javascript from i18n yaml files
|
32
|
+
# appropriate for i18n-js
|
33
|
+
# @param [Array<FileWrapper>] inputs an Array of
|
34
|
+
# {FileWrapper} objects representing the inputs to
|
35
|
+
# this filter.
|
36
|
+
# @param [FileWrapper] output a single {FileWrapper}
|
37
|
+
# object representing the output.
|
38
|
+
def generate_output(inputs, output)
|
39
|
+
js_dec = 'I18n.translations = I18n.translations || {};'
|
40
|
+
output_hash = {}
|
41
|
+
inputs.each do |input|
|
42
|
+
output_hash.deep_merge! YAML.load(input.read)
|
43
|
+
end
|
44
|
+
output.write "#{js_dec}\nI18n.translations = #{output_hash.to_json};"
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def external_dependencies
|
50
|
+
[ 'yaml', 'json' ]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rake-pipeline"
|
2
|
+
|
3
|
+
module Rake
|
4
|
+
class Pipeline
|
5
|
+
module I18n
|
6
|
+
module Filters
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require "ext/hash"
|
13
|
+
require "rake-pipeline-i18n-filters/version"
|
14
|
+
require "rake-pipeline-i18n-filters/filter_with_dependencies"
|
15
|
+
require "rake-pipeline-i18n-filters/i18n_js_filter"
|
16
|
+
require "rake-pipeline-i18n-filters/ember_strings_filter"
|
17
|
+
require "rake-pipeline-i18n-filters/helpers"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rake-pipeline-i18n-filters/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Randy Morgan"]
|
6
|
+
gem.email = ["digital.ipseity@gmail.com"]
|
7
|
+
gem.description = %q{A collection of i18n filters for rake-pipeline}
|
8
|
+
gem.summary = %q{Adds filters for generating i18n-js and Ember.STRINGS localization data from i18n YAML}
|
9
|
+
gem.homepage = "http://github.com/randym/rake-pipeline-i18n-filters"
|
10
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
gem.name = "rake-pipeline-i18n-filters"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Rake::Pipeline::I18n::Filters::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency "rake-pipeline", "~> 0.6"
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
describe "EmberStringsFilter" do
|
4
|
+
EmberStringsFilter ||= Rake::Pipeline::I18n::Filters::EmberStringsFilter
|
5
|
+
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
6
|
+
|
7
|
+
# Seems like YAML is expecting this method.
|
8
|
+
MemoryFileWrapper.class_eval( 'def external_encoding; Encoding.default_external; end')
|
9
|
+
|
10
|
+
let(:input) { yaml = <<EOF
|
11
|
+
# encoding: UTF-8
|
12
|
+
en:
|
13
|
+
foo: bar
|
14
|
+
hoge: hoge
|
15
|
+
ja:
|
16
|
+
foo: バー
|
17
|
+
hoge: ホゲ
|
18
|
+
EOF
|
19
|
+
}
|
20
|
+
|
21
|
+
# not using heredoc as it adds an extra \n to the end
|
22
|
+
let(:expected_ember_strings) {
|
23
|
+
"EmberI18n = EmberI18n || {};EmberI18n['en'] = { 'foo' : 'bar','hoge' : 'hoge' };EmberI18n['ja'] = { 'foo' : 'バー','hoge' : 'ホゲ' };"
|
24
|
+
}
|
25
|
+
def input_file(name, content)
|
26
|
+
MemoryFileWrapper.new('/path/to/input', name, 'UTF-8', content)
|
27
|
+
end
|
28
|
+
|
29
|
+
def output_file(name)
|
30
|
+
MemoryFileWrapper.new('/path/to/output', name, 'UTF-8')
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_filter(filter)
|
34
|
+
filter.file_wrapper_class = MemoryFileWrapper
|
35
|
+
filter.input_files = [input_file('localizations.yml', input)]
|
36
|
+
filter.output_root = '/path/to/output'
|
37
|
+
filter.rake_application = Rake::Application.new
|
38
|
+
filter
|
39
|
+
end
|
40
|
+
|
41
|
+
it "generates ember_strings" do
|
42
|
+
filter = setup_filter EmberStringsFilter.new
|
43
|
+
filter.output_files.should == [output_file('localizations.js')]
|
44
|
+
tasks = filter.generate_rake_tasks
|
45
|
+
tasks.each(&:invoke)
|
46
|
+
file = MemoryFileWrapper.files['/path/to/output/localizations.js']
|
47
|
+
file.body.should == expected_ember_strings
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe "Helpers" do
|
2
|
+
let(:pipeline) { Rake::Pipeline.new }
|
3
|
+
let(:dsl) { Rake::Pipeline::DSL::PipelineDSL.new(pipeline) }
|
4
|
+
|
5
|
+
before do
|
6
|
+
pipeline.add_input '.'
|
7
|
+
end
|
8
|
+
|
9
|
+
def filter
|
10
|
+
pipeline.filters.last
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#i18n_js' do
|
14
|
+
it "creates an I18nJsFilter" do
|
15
|
+
dsl.i18n_js
|
16
|
+
filter.should be_kind_of(Rake::Pipeline::I18n::Filters::I18nJsFilter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe '#ember_strings' do
|
20
|
+
it "creates an EmberStringsFilter" do
|
21
|
+
dsl.ember_strings
|
22
|
+
filter.should be_kind_of(Rake::Pipeline::I18n::Filters::EmberStringsFilter)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
describe "I18nJsFilter" do
|
4
|
+
I18nJsFilter ||= Rake::Pipeline::I18n::Filters::I18nJsFilter
|
5
|
+
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
6
|
+
|
7
|
+
# Seems like YAML is expecting this method.
|
8
|
+
MemoryFileWrapper.class_eval( 'def external_encoding; Encoding.default_external; end')
|
9
|
+
|
10
|
+
let(:input) { yaml = <<EOF
|
11
|
+
# encoding: UTF-8
|
12
|
+
en:
|
13
|
+
foo: bar
|
14
|
+
hoge: hoge
|
15
|
+
ja:
|
16
|
+
foo: バー
|
17
|
+
hoge: ホゲ
|
18
|
+
EOF
|
19
|
+
}
|
20
|
+
|
21
|
+
# not using heredoc as it adds an extra \n to the end
|
22
|
+
let(:expected_i18n_js) {
|
23
|
+
"I18n.translations = I18n.translations || {};\nI18n.translations = {\"en\":{\"foo\":\"bar\",\"hoge\":\"hoge\"},\"ja\":{\"foo\":\"バー\",\"hoge\":\"ホゲ\"}};"
|
24
|
+
}
|
25
|
+
def input_file(name, content)
|
26
|
+
MemoryFileWrapper.new('/path/to/input', name, 'UTF-8', content)
|
27
|
+
end
|
28
|
+
|
29
|
+
def output_file(name)
|
30
|
+
MemoryFileWrapper.new('/path/to/output', name, 'UTF-8')
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_filter(filter)
|
34
|
+
filter.file_wrapper_class = MemoryFileWrapper
|
35
|
+
filter.input_files = [input_file('i18n_js_localizations.yml', input)]
|
36
|
+
filter.output_root = '/path/to/output'
|
37
|
+
filter.rake_application = Rake::Application.new
|
38
|
+
filter
|
39
|
+
end
|
40
|
+
|
41
|
+
it "generates i18n_js" do
|
42
|
+
filter = setup_filter I18nJsFilter.new
|
43
|
+
filter.output_files.should == [output_file('i18n_js_localizations.js')]
|
44
|
+
tasks = filter.generate_rake_tasks
|
45
|
+
tasks.each(&:invoke)
|
46
|
+
file = MemoryFileWrapper.files['/path/to/output/i18n_js_localizations.js']
|
47
|
+
file.body.should == expected_i18n_js
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require "rake-pipeline"
|
2
|
+
require "rake-pipeline-i18n-filters"
|
3
|
+
class Rake::Pipeline
|
4
|
+
module SpecHelpers
|
5
|
+
|
6
|
+
class MemoryFileWrapper < Struct.new(:root, :path, :encoding, :body)
|
7
|
+
@@files = {}
|
8
|
+
@@data = {}
|
9
|
+
|
10
|
+
def self.files
|
11
|
+
@@files
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.data
|
15
|
+
@@data
|
16
|
+
end
|
17
|
+
|
18
|
+
def with_encoding(new_encoding)
|
19
|
+
self.class.new(root, path, new_encoding, body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def fullpath
|
23
|
+
File.join(root, path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@@files[fullpath] = self
|
28
|
+
self.body = ""
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
|
32
|
+
def read
|
33
|
+
body || @@data[fullpath] || ""
|
34
|
+
end
|
35
|
+
|
36
|
+
def write(contents)
|
37
|
+
self.body << contents
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# TODO: OS agnostic modules
|
42
|
+
module FileUtils
|
43
|
+
def mkdir_p(dir)
|
44
|
+
system "mkdir", "-p", dir
|
45
|
+
end
|
46
|
+
|
47
|
+
def touch(file)
|
48
|
+
system "touch", file
|
49
|
+
end
|
50
|
+
|
51
|
+
def rm_rf(dir)
|
52
|
+
system "rm", "-rf", dir
|
53
|
+
end
|
54
|
+
|
55
|
+
def touch_p(file)
|
56
|
+
dir = File.dirname(file)
|
57
|
+
mkdir_p dir
|
58
|
+
touch file
|
59
|
+
end
|
60
|
+
|
61
|
+
def age_existing_files
|
62
|
+
old_time = Time.now - 10
|
63
|
+
Dir[File.join(tmp, "**/*.js")].each do |file|
|
64
|
+
File.utime(old_time, old_time, file)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module Filters
|
70
|
+
ConcatFilter = Rake::Pipeline::ConcatFilter
|
71
|
+
MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
72
|
+
|
73
|
+
class StripAssertsFilter < Rake::Pipeline::Filter
|
74
|
+
def generate_output(inputs, output)
|
75
|
+
inputs.each do |input|
|
76
|
+
output.write input.read.gsub(%r{^\s*assert\(.*\)\s*;?\s*$}m, '')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
RSpec.configure do |config|
|
85
|
+
original = Dir.pwd
|
86
|
+
|
87
|
+
config.include Rake::Pipeline::SpecHelpers::FileUtils
|
88
|
+
|
89
|
+
def tmp
|
90
|
+
File.expand_path("../tmp", __FILE__)
|
91
|
+
end
|
92
|
+
|
93
|
+
config.before do
|
94
|
+
rm_rf(tmp)
|
95
|
+
mkdir_p(tmp)
|
96
|
+
Dir.chdir(tmp)
|
97
|
+
end
|
98
|
+
|
99
|
+
config.after do
|
100
|
+
Dir.chdir(original)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rake-pipeline-i18n-filters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Randy Morgan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake-pipeline
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.6'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A collection of i18n filters for rake-pipeline
|
47
|
+
email:
|
48
|
+
- digital.ipseity@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- .yardopts
|
56
|
+
- Gemfile
|
57
|
+
- README.markdown
|
58
|
+
- README.yard
|
59
|
+
- Rakefile
|
60
|
+
- lib/ext/hash.rb
|
61
|
+
- lib/rake-pipeline-i18n-filters.rb
|
62
|
+
- lib/rake-pipeline-i18n-filters/ember_strings_filter.rb
|
63
|
+
- lib/rake-pipeline-i18n-filters/filter_with_dependencies.rb
|
64
|
+
- lib/rake-pipeline-i18n-filters/helpers.rb
|
65
|
+
- lib/rake-pipeline-i18n-filters/i18n_js_filter.rb
|
66
|
+
- lib/rake-pipeline-i18n-filters/version.rb
|
67
|
+
- rake-pipeline-i18n-filters.gemspec
|
68
|
+
- spec/ember_strings_filter_spec.rb
|
69
|
+
- spec/helpers_spec.rb
|
70
|
+
- spec/i18n_js_filter_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: http://github.com/randym/rake-pipeline-i18n-filters
|
73
|
+
licenses: []
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
hash: -3126436427769998385
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: -3126436427769998385
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.24
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Adds filters for generating i18n-js and Ember.STRINGS localization data from
|
102
|
+
i18n YAML
|
103
|
+
test_files:
|
104
|
+
- spec/ember_strings_filter_spec.rb
|
105
|
+
- spec/helpers_spec.rb
|
106
|
+
- spec/i18n_js_filter_spec.rb
|
107
|
+
- spec/spec_helper.rb
|