guard-i18next 0.1a

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.
@@ -0,0 +1,52 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ module Guard
7
+ class I18next < Guard
8
+
9
+ DEFAULT_OPTIONS = {
10
+ :output => Pathname.pwd.join('app', 'assets', 'javascripts', 'i18n')
11
+ :namespace => '(global || window).Locales'
12
+ }
13
+
14
+
15
+ # Initialize Guard::i18next
16
+ #
17
+ # @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
18
+ # @param [Hash] options the options for the Guard
19
+ # @option options [String] :output the output directory
20
+ #
21
+ def initialize(watchers = [], options = {})
22
+ watchers = [] if !watchers
23
+ defaults = DEFAULT_OPTIONS.clone
24
+
25
+ super(watchers, defaults.merge(options))
26
+ end
27
+
28
+ # Gets called when watched paths and files have changes.
29
+ #
30
+ # @param [Array<String>] paths the changed paths and files
31
+ # @raise [:task_has_failed] when stop has failed
32
+ #
33
+ def run_on_change(paths)
34
+ Dir::mkdir(options(:output)) unless File.directory?(options(:output))
35
+
36
+ paths.each do |locale_path|
37
+ filename = File.basename(locale_path, ".yml")
38
+ input = File.new(locale_path, 'r')
39
+ locale = YAML.load(input.read)
40
+ input.close
41
+
42
+ locale_key = locale.keys[0]
43
+ content = locale[locale_key]
44
+ File.open(options(:output) + "#{filename}.js", "w") do |f|
45
+ # Initialize namespace (if it hasn't been already)
46
+ f.puts "#{options(:namespace)} = #{options(:namespace)} != null ? #{options(:namespace)} : {}"
47
+ f.puts options(:namespace) + "[#{locale_key}] = " + content.to_json
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,7 @@
1
+ require "guard/i18next"
2
+
3
+ # Look for modifications for languages yml
4
+ guard 'i18next' do
5
+ watch(%r{config/locales/.+\.yml$})
6
+ end
7
+
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ class I18nextVersion
3
+ VERSION = "0.1a"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-i18next
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1a
5
+ prerelease: 3
6
+ platform: ruby
7
+ authors:
8
+ - Jared Scott
9
+ - Nicolas ZERMATI
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: guard
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Automatically generate js files from locales files for consumption by
48
+ i18next.js.
49
+ email:
50
+ - gecko@uw.edu
51
+ - nicoolas25@gmail.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - lib/guard/i18next/templates/Guardfile
57
+ - lib/guard/i18next/version.rb
58
+ - lib/guard/i18next.rb
59
+ homepage: ''
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>'
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.24
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Automatically generate js files from locales files for consumption by i18next.js.
83
+ test_files: []