Permalink
Browse files

extract thor tasks into Cldr::Thor in order to not require Thor by de…

…fault
  • Loading branch information...
1 parent 70df264 commit 5947d9966b46f7e198d028521d994ab515c07568 Sven Fuchs committed Jan 9, 2010
Showing with 56 additions and 43 deletions.
  1. +14 −7 README.textile
  2. +1 −1 Rakefile
  3. +4 −1 cldr.gemspec
  4. +1 −1 cldr.thor
  5. +1 −25 lib/cldr.rb
  6. +2 −8 lib/cldr/download.rb
  7. +33 −0 lib/cldr/thor.rb
View
@@ -8,21 +8,28 @@ This library is a first stab at that goal. You can export CLDR data to YAML and
h2. Requirements
-* Ruby 1.9 (if you want well-ordered Hashes)
-* Thor
+ * Ruby 1.9 (if you want well-ordered Hashes)
+ * Thor
+
+h2. Installation
+
+<pre>
+gem install cldr (not there, yet. install locally)
+thor install http://github.com/svenfuchs/cldr/raw/master/cldr.thor --as=cldr
+</pre>
h2. Usage
This will export all known components from all locales to the target directory ./data/[locale]/[component].{yml,rb}:
<pre>
- $ thor cldr:export
+$ thor cldr:export
</pre>
You can also optionally specify locales and/or components to export as well as the target directory:
<pre>
- $ thor cldr:export --locales de fr en --components numbers plurals --target=./tmp/export
+$ thor cldr:export --locales de fr en --components numbers plurals --target=./tmp/export
</pre>
This will export the components :numbers and :plurals from the locales :de, :fr and :en to the same target directory.
@@ -32,7 +39,7 @@ Also note that CLDR natively builds on a locale fallback concept where all local
By default this library just exports data that is present in CLDR for a given locale. If you do not want to use locale fallbacks in your application you'll need to "flatten" locale fallbacks and merge the data during export time. To do that you can use the --merge option:
<pre>
- $ thor cldr:export --merge
+$ thor cldr:export --merge
</pre>
@@ -41,6 +48,6 @@ h2. Resources
For additional information on CLDR plural rules see:
-* "http://unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules":http://unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules
-* "http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html":http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html
+ * "http://unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules":http://unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules
+ * "http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html":http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html
View
@@ -10,7 +10,7 @@ begin
gem.email = "svenfuchs@artweb-design.de"
gem.homepage = "http://github.com/svenfuchs/cldr"
gem.authors = ["Sven Fuchs"]
- gem.files = FileList["clrd.thor", "[A-Z]*", "{lib,test}/**/*"]
+ gem.files = FileList["*.thor", "[A-Z]*", "{lib,test}/**/*"]
end
Jeweler::GemcutterTasks.new
rescue LoadError
View
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Sven Fuchs"]
s.date = %q{2010-01-09}
- s.description = %q{Ruby library for exporting and using data from CLDR}
+ s.description = %q{Ruby library for exporting and using data from CLDR, see http://cldr.unicode.org}
s.email = %q{svenfuchs@artweb-design.de}
s.extra_rdoc_files = [
"LICENSE",
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
"Rakefile",
"TODO",
"VERSION",
+ "cldr.thor",
"lib/cldr.rb",
"lib/cldr/data.rb",
"lib/cldr/data/base.rb",
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
"lib/cldr/data/plurals/rules.rb",
"lib/cldr/data/territories.rb",
"lib/cldr/data/units.rb",
+ "lib/cldr/download.rb",
"lib/cldr/export.rb",
"lib/cldr/export/ruby.rb",
"lib/cldr/export/yaml.rb",
@@ -47,6 +49,7 @@ Gem::Specification.new do |s|
"lib/cldr/format/integer.rb",
"lib/cldr/format/number.rb",
"lib/cldr/format/numeric.rb",
+ "lib/cldr/thor.rb",
"lib/core_ext/hash/deep_merge.rb",
"lib/core_ext/hash/deep_stringify_keys.rb",
"lib/core_ext/hash/symbolize_keys.rb",
View
@@ -2,4 +2,4 @@ $:.unshift(File.dirname(__FILE__) + '/lib')
require 'rubygems'
require 'thor'
-require 'cldr'
+require 'cldr/thor'
View
@@ -1,32 +1,8 @@
require 'rubygems'
-require 'thor'
require 'core_ext/hash/symbolize_keys'
-class Cldr < Thor
+class Cldr
autoload :Data, 'cldr/data'
autoload :Export, 'cldr/export'
autoload :Format, 'cldr/format'
-
- desc "export [--locales=de fr en] [--components=numbers plurals] [--target=./data] [--merge]",
- "Export CLDR data by locales and components to target dir"
- method_options %w(locales -l) => :array,
- %w(components -l) => :array,
- %w(target -t) => :string,
- %w(merge -m) => :boolean
-
- def export
- $stdout.sync
- Cldr::Export.export(options.dup.symbolize_keys) { putc '.' }
- puts
- end
-
- desc "download [--source=http://unicode.org/Public/cldr/1.7.2/core.zip] [--target=./vendor]",
- "Download and extract CLDR data from source to target dir"
- method_options %w(source -s) => :string,
- %w(target -t) => :string
-
- def download
- require 'cldr/download'
- Cldr.download(options['source'], options['target'])
- end
end
View
@@ -12,15 +12,9 @@ def download(source = nil, target = nil)
source = URI.parse(source)
tempfile = Tempfile.new('cldr-core')
- Net::HTTP.start(source.host) do |http|
- response = http.get(source.path)
- File.open(tempfile, "wb") { |f| f.write(response.body) }
- end
-
+ system("curl #{source} -o #{tempfile.path}")
FileUtils.mkdir_p(target)
- `unzip #{tempfile.path} -d #{target}`
-
- puts "extracted #{source} to #{target}"
+ system("unzip #{tempfile.path} -d #{target}")
end
end
end
View
@@ -0,0 +1,33 @@
+require 'thor'
+require 'cldr'
+
+class Cldr
+ class Thor < ::Thor
+ namespace 'cldr'
+
+ desc "download [--source=http://unicode.org/Public/cldr/1.7.2/core.zip] [--target=./vendor]",
+ "Download and extract CLDR data from source to target dir"
+ method_options %w(source -s) => :string,
+ %w(target -t) => :string
+
+ def download
+ require 'cldr/download'
+ Cldr.download(options['source'], options['target'])
+ end
+
+ desc "export [--locales=de fr en] [--components=numbers plurals] [--target=./data] [--merge]",
+ "Export CLDR data by locales and components to target dir"
+ method_options %w(locales -l) => :array,
+ %w(components -l) => :array,
+ %w(target -t) => :string,
+ %w(merge -m) => :boolean
+
+ def export
+ $stdout.sync
+ Cldr::Export.export(options.dup.symbolize_keys) { putc '.' }
+ puts
+ end
+
+ # TODO flatten task, e.g. flatten all plural locale files into one big file
+ end
+end

0 comments on commit 5947d99

Please sign in to comment.