localized 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- localized (0.0.4)
4
+ localized (0.0.5)
5
+ bitfields (>= 0.4.0)
5
6
  rails (>= 3.0)
6
7
 
7
8
  GEM
@@ -37,11 +38,15 @@ GEM
37
38
  archive-tar-minitar (0.5.2)
38
39
  arel (1.0.1)
39
40
  activesupport (~> 3.0.0)
41
+ bitfields (0.4.0)
40
42
  builder (2.1.2)
41
43
  columnize (0.3.4)
42
44
  diff-lcs (1.1.2)
43
45
  erubis (2.6.6)
44
46
  abstract (>= 1.0.0)
47
+ generator_spec (0.8.3)
48
+ rails (~> 3.0)
49
+ rspec-rails
45
50
  i18n (0.4.2)
46
51
  linecache19 (0.5.12)
47
52
  ruby_core_source (>= 0.1.4)
@@ -103,6 +108,7 @@ PLATFORMS
103
108
  ruby
104
109
 
105
110
  DEPENDENCIES
111
+ generator_spec
106
112
  localized!
107
113
  rspec (= 2.6.0)
108
114
  rspec-rails (= 2.6.0)
@@ -0,0 +1,56 @@
1
+ class LocalizedGenerator < Rails::Generators::Base
2
+ desc "This generator copies a sample localized.yml and creates a concerns for
3
+ scopes and site flags on active record models."
4
+ argument :sites, :type => :array, :default => ['us:en-US', 'uk:en-UK', 'it:it-IT'], :banner => "site:locale us:en-US"
5
+
6
+ def create_localized_config
7
+ # create the
8
+ create_file "config/localized.yml", <<-YAML_FILE
9
+ # this file was originally generated by the localized generator
10
+ default_host_prefix: 'www.'
11
+ default_site: 'us'
12
+ site_locale_map:
13
+ #{generate_yaml_from_sites}
14
+ YAML_FILE
15
+ end
16
+
17
+ desc "create the concerns mixin for adding bitfield and default scope support"
18
+ def create_concerns_lib
19
+ create_file "app/concerns/localized/sites.rb", <<-SITES
20
+ # this file was originally generated by the localized generator
21
+ module Localized::Sites
22
+ extend ActiveSupport::Concern
23
+
24
+ included do
25
+ # create bitfield for all supported sites
26
+ include Bitfields
27
+ # NOTE: order should not change, if it does site data may become corrupt.
28
+ bitfield :sites,
29
+ #{generate_flags}
30
+
31
+ # default scope to filter by current locale to site map
32
+ default_scope self.send(Localized::Config.locale_to_site_map[I18n.locale])
33
+ end
34
+ end
35
+ SITES
36
+ end
37
+
38
+ private
39
+
40
+ def generate_flags
41
+ flag_idx = 0
42
+ parsed_sites.map(&:first).map do |s|
43
+ flag_idx = flag_idx == 0 ? 1 : flag_idx * 2
44
+ " #{flag_idx} => :#{s},"
45
+ end.join("\n").chop
46
+ end
47
+
48
+ def generate_yaml_from_sites
49
+ parsed_sites.map { |(s,l)| " #{s.strip}: '#{l.strip}'"}.join("\n")
50
+ end
51
+
52
+ def parsed_sites
53
+ sites.compact.map{|s| [*s.split(':')]}
54
+ end
55
+
56
+ end
@@ -7,10 +7,10 @@ module Localized; end
7
7
  require 'localized/config'
8
8
  require 'localized/helper'
9
9
  require 'localized/convert'
10
+ require 'bitfields'
10
11
 
11
12
  # load the modules into the rails world
12
13
  [
13
- ActionView::Base,
14
+ ActionView::Base,
14
15
  ActionController::Base
15
16
  ].each { |mod| mod.send :include, Localized::Helper }
16
-
@@ -2,15 +2,17 @@ Gem::Specification.new do |s|
2
2
  s.name = 'localized'
3
3
  s.author = 'Paul Hepworth'
4
4
  s.email = 'paul<dot>hepworth<at>peppyheppy<dot>com'
5
- s.version = '0.0.5'
5
+ s.version = '0.0.6'
6
6
  s.homepage = 'https://github.com/peppyheppy/localized'
7
7
  s.date = '2011-07-09'
8
8
  s.summary = "A ruby on rails gem that provides locale setting support through the subdomain (in a box)"
9
9
  s.description = "This gem allows you to set locale using a subdomain and url helper support for switching sites."
10
10
  s.files = s.files = `git ls-files`.split("\n")
11
11
  s.add_runtime_dependency "rails", ">= 3.0"
12
+ s.add_runtime_dependency "bitfields", ">= 0.4.0"
12
13
  s.add_development_dependency "ruby-debug19"
13
14
  s.add_development_dependency "rspec", "2.6.0"
14
15
  s.add_development_dependency "rspec-rails", "2.6.0"
16
+ s.add_development_dependency "generator_spec"
15
17
  end
16
18
 
@@ -0,0 +1,74 @@
1
+ if __FILE__ == $0
2
+ puts "Run with: watchr #{__FILE__}. \n\nRequired gems: watchr rev"
3
+ exit 1
4
+ end
5
+
6
+ # --------------------------------------------------
7
+ # Convenience Methods
8
+ # --------------------------------------------------
9
+ def run(cmd)
10
+ puts(cmd)
11
+ system(cmd)
12
+ end
13
+
14
+ def run_all_specs
15
+ run "rake -s spec"
16
+ end
17
+
18
+ def run_single_spec *spec
19
+ spec = spec.join(' ')
20
+ run "rspec -O spec/spec.opts #{spec}"
21
+ end
22
+
23
+ def run_specs_with_shared_examples(shared_example_filename, spec_path = 'spec')
24
+
25
+ # Returns the names of the shared examples in filename
26
+ def shared_examples(filename)
27
+ lines = File.readlines(filename)
28
+ lines.grep(/shared_examples_for[\s'"]+(.+)['"]\s*[do|\{]/) do |matching_line|
29
+ $1
30
+ end
31
+ end
32
+
33
+ # Returns array with filenames of the specs using shared_example
34
+ def specs_with_shared_example(shared_example, path)
35
+ command = "grep -lrE 'it_should_behave_like .(#{shared_example}).' #{path}"
36
+ `#{command}`.split
37
+ end
38
+
39
+ shared_examples(shared_example_filename).each do |shared_example|
40
+ specs_to_run = specs_with_shared_example(shared_example, spec_path)
41
+ run_single_spec(specs_to_run) unless specs_to_run.empty?
42
+ end
43
+
44
+ end
45
+
46
+ def run_cucumber_scenario scenario_path
47
+ run "cucumber #{scenario_path}"
48
+ end
49
+
50
+ # --------------------------------------------------
51
+ # Watchr Rules
52
+ # --------------------------------------------------
53
+ watch( '^spec/spec_helper\.rb' ) { run_all_specs }
54
+ watch( '^spec/shared_behaviors/.*\.rb' ) { |m| run_specs_with_shared_examples(m[0]) }
55
+ watch( '^spec/.*_spec\.rb' ) { |m| run_single_spec(m[0]) }
56
+ watch( '^app/(.*)\.rb' ) { |m| run_single_spec("spec/%s_spec.rb" % m[1]) }
57
+ watch( '^app/views/(.*)\.haml' ) { |m| run_single_spec("spec/views/%s.haml_spec.rb" % m[1]) }
58
+ watch( '^lib/(.*)\.rb' ) { |m| run_single_spec("spec/lib/%s_spec.rb" % m[1] ) }
59
+ watch( '^features/.*\.feature' ) { |m| run_cucumber_scenario(m[0]) }
60
+
61
+
62
+ # --------------------------------------------------
63
+ # Signal Handling
64
+ # --------------------------------------------------
65
+ # Ctrl-\
66
+ Signal.trap('QUIT') do
67
+ puts " --- Running all tests ---\n\n"
68
+ run_all_specs
69
+ end
70
+
71
+ # Ctrl-C
72
+ Signal.trap('INT') { abort("\n") }
73
+
74
+ puts "Watching.."
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require "generator_spec/test_case"
3
+ require 'generators/localized/localized_generator'
4
+
5
+ describe LocalizedGenerator do
6
+ include GeneratorSpec::TestCase
7
+ destination File.expand_path("../../../../tmp", __FILE__)
8
+
9
+ before do
10
+ prepare_destination
11
+ run_generator
12
+ end
13
+
14
+ specify do
15
+ destination_root.should have_structure {
16
+ no_file "sites.rb"
17
+ directory "app" do
18
+ directory "concerns" do
19
+ directory "localized" do
20
+ file "sites.rb" do
21
+ contains "# this file was originally generated by the localized generator"
22
+ contains "module Localized::Sites"
23
+ contains "bitfield :sites,"
24
+ contains "default_scope"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ no_file "localized.yml"
30
+ directory "config" do
31
+ file "localized.yml" do
32
+ contains "# this file was originally generated by the localized generator"
33
+ contains "default_site"
34
+ contains "us: 'en-US'"
35
+ end
36
+ end
37
+ }
38
+ end
39
+ end
40
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: localized
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paul Hepworth
@@ -25,38 +25,60 @@ dependencies:
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby-debug19
28
+ name: bitfields
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.4.0
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: ruby-debug19
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
31
42
  none: false
32
43
  requirements:
33
44
  - - ">="
34
45
  - !ruby/object:Gem::Version
35
46
  version: "0"
36
47
  type: :development
37
- version_requirements: *id002
48
+ version_requirements: *id003
38
49
  - !ruby/object:Gem::Dependency
39
50
  name: rspec
40
51
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirement: &id004 !ruby/object:Gem::Requirement
42
53
  none: false
43
54
  requirements:
44
55
  - - "="
45
56
  - !ruby/object:Gem::Version
46
57
  version: 2.6.0
47
58
  type: :development
48
- version_requirements: *id003
59
+ version_requirements: *id004
49
60
  - !ruby/object:Gem::Dependency
50
61
  name: rspec-rails
51
62
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
63
+ requirement: &id005 !ruby/object:Gem::Requirement
53
64
  none: false
54
65
  requirements:
55
66
  - - "="
56
67
  - !ruby/object:Gem::Version
57
68
  version: 2.6.0
58
69
  type: :development
59
- version_requirements: *id004
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: generator_spec
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
60
82
  description: This gem allows you to set locale using a subdomain and url helper support for switching sites.
61
83
  email: paul<dot>hepworth<at>peppyheppy<dot>com
62
84
  executables: []
@@ -74,16 +96,19 @@ files:
74
96
  - Rakefile
75
97
  - config/.DS_Store
76
98
  - config/defaults.yml
99
+ - lib/generators/localized/localized_generator.rb
77
100
  - lib/localized.rb
78
101
  - lib/localized/config.rb
79
102
  - lib/localized/convert.rb
80
103
  - lib/localized/helper.rb
81
104
  - localized.gemspec
105
+ - rspec_watcher.rb
82
106
  - spec/config/locales/en-US.yml
83
107
  - spec/config/locales/es-ES.yml
84
108
  - spec/config/locales/nl-NL.yml
85
109
  - spec/config/localized.yml
86
110
  - spec/config/routes.rb
111
+ - spec/lib/generators/localized_generator_spec.rb
87
112
  - spec/lib/localized/config_spec.rb
88
113
  - spec/lib/localized/convert_spec.rb
89
114
  - spec/lib/localized/helper_spec.rb