nulogy-gettext_i18n_rails 0.4.6.1

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.
Files changed (33) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +126 -0
  3. data/Rakefile +24 -0
  4. data/Readme.md +226 -0
  5. data/VERSION +1 -0
  6. data/gettext_i18n_rails.gemspec +65 -0
  7. data/init.rb +14 -0
  8. data/lib/gettext_i18n_rails.rb +33 -0
  9. data/lib/gettext_i18n_rails/action_controller.rb +8 -0
  10. data/lib/gettext_i18n_rails/active_record.rb +19 -0
  11. data/lib/gettext_i18n_rails/backend.rb +67 -0
  12. data/lib/gettext_i18n_rails/base_parser.rb +41 -0
  13. data/lib/gettext_i18n_rails/haml_parser.rb +15 -0
  14. data/lib/gettext_i18n_rails/hamlet_parser.rb +16 -0
  15. data/lib/gettext_i18n_rails/html_safe_translations.rb +29 -0
  16. data/lib/gettext_i18n_rails/i18n_hacks.rb +25 -0
  17. data/lib/gettext_i18n_rails/model_attributes_finder.rb +108 -0
  18. data/lib/gettext_i18n_rails/railtie.rb +22 -0
  19. data/lib/gettext_i18n_rails/ruby_gettext_extractor.rb +144 -0
  20. data/lib/gettext_i18n_rails/slim_parser.rb +15 -0
  21. data/lib/gettext_i18n_rails/string_interpolate_fix.rb +20 -0
  22. data/lib/gettext_i18n_rails/tasks.rb +127 -0
  23. data/lib/tasks/gettext_rails_i18n.rake +1 -0
  24. data/spec/gettext_i18n_rails/action_controller_spec.rb +54 -0
  25. data/spec/gettext_i18n_rails/active_record_spec.rb +85 -0
  26. data/spec/gettext_i18n_rails/backend_spec.rb +56 -0
  27. data/spec/gettext_i18n_rails/haml_parser_spec.rb +39 -0
  28. data/spec/gettext_i18n_rails/hamlet_parser_spec.rb +33 -0
  29. data/spec/gettext_i18n_rails/slim_parser_spec.rb +40 -0
  30. data/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb +32 -0
  31. data/spec/gettext_i18n_rails_spec.rb +84 -0
  32. data/spec/spec_helper.rb +39 -0
  33. metadata +110 -0
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+ require "gettext_i18n_rails/string_interpolate_fix"
3
+
4
+ describe "String#%" do
5
+ it "is not safe if it was not safe" do
6
+ result = ("<br/>%{x}" % {:x => 'a'})
7
+ result.should == '<br/>a'
8
+ result.html_safe?.should == false
9
+ end
10
+
11
+ xit "stays safe if it was safe" do
12
+ result = ("<br/>%{x}".html_safe % {:x => 'a'})
13
+ result.should == '<br/>a'
14
+ result.html_safe?.should == true
15
+ end
16
+
17
+ xit "escapes unsafe added to safe" do
18
+ result = ("<br/>%{x}".html_safe % {:x => '<br/>'})
19
+ result.should == '<br/>&lt;br/&gt;'
20
+ result.html_safe?.should == true
21
+ end
22
+
23
+ it "does not escape unsafe if it was unsafe" do
24
+ result = ("<br/>%{x}" % {:x => '<br/>'})
25
+ result.should == '<br/><br/>'
26
+ result.html_safe?.should == false
27
+ end
28
+
29
+ it "does not break array replacement" do
30
+ "%ssd" % ['a'].should == "asd"
31
+ end
32
+ end
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ FastGettext.silence_errors
4
+
5
+ describe GettextI18nRails do
6
+ before do
7
+ GettextI18nRails.translations_are_html_safe = nil
8
+ end
9
+
10
+ it "extends all classes with fast_gettext" do
11
+ _('test')
12
+ end
13
+
14
+ describe 'translations_are_html_safe' do
15
+ before do
16
+ GettextI18nRails.translations_are_html_safe = nil
17
+ end
18
+
19
+ it "makes translations not html_safe by default" do
20
+ _('x').html_safe?.should == false
21
+ s_('x').html_safe?.should == false
22
+ n_('x','y',2).html_safe?.should == false
23
+ String._('x').html_safe?.should == false
24
+ String.s_('x').html_safe?.should == false
25
+ String.n_('x','y',2).html_safe?.should == false
26
+ end
27
+
28
+ it "makes instance translations html_safe when wanted" do
29
+ GettextI18nRails.translations_are_html_safe = true
30
+ _('x').html_safe?.should == true
31
+ s_('x').html_safe?.should == true
32
+ n_('x','y',2).html_safe?.should == true
33
+ end
34
+
35
+ it "makes class translations html_safe when wanted" do
36
+ GettextI18nRails.translations_are_html_safe = true
37
+ String._('x').html_safe?.should == true
38
+ String.s_('x').html_safe?.should == true
39
+ String.n_('x','y',2).html_safe?.should == true
40
+ end
41
+
42
+ it "does not make everything html_safe" do
43
+ 'x'.html_safe?.should == false
44
+ end
45
+ end
46
+
47
+ it "sets up out backend" do
48
+ I18n.backend.is_a?(GettextI18nRails::Backend).should be_true
49
+ end
50
+
51
+ it "has a VERSION" do
52
+ GettextI18nRails::VERSION.should =~ /^\d+\.\d+\.\d+$/
53
+ end
54
+
55
+ describe 'FastGettext I18n interaction' do
56
+ before do
57
+ FastGettext.available_locales = nil
58
+ FastGettext.locale = 'de'
59
+ end
60
+
61
+ it "links FastGettext with I18n locale" do
62
+ FastGettext.locale = 'xx'
63
+ I18n.locale.should == :xx
64
+ end
65
+
66
+ it "does not set an not-accepted locale to I18n.locale" do
67
+ FastGettext.available_locales = ['de']
68
+ FastGettext.locale = 'xx'
69
+ I18n.locale.should == :de
70
+ end
71
+
72
+ it "links I18n.locale and FastGettext.locale" do
73
+ I18n.locale = :yy
74
+ FastGettext.locale.should == 'yy'
75
+ end
76
+
77
+ it "does not set a non-available locale though I18n.locale" do
78
+ FastGettext.available_locales = ['de']
79
+ I18n.locale = :xx
80
+ FastGettext.locale.should == 'de'
81
+ I18n.locale.should == :de
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
4
+
5
+ require 'tempfile'
6
+ require 'active_support'
7
+ require 'active_record'
8
+ require 'action_controller'
9
+ require 'action_mailer'
10
+ require 'fast_gettext'
11
+ require 'gettext_i18n_rails'
12
+
13
+ begin
14
+ Gem.all_load_paths
15
+ rescue
16
+ puts "Fixing Gem.all_load_paths"
17
+ module Gem;def self.all_load_paths;[];end;end
18
+ end
19
+
20
+ module Rails
21
+ def self.root
22
+ File.dirname(__FILE__)
23
+ end
24
+
25
+ module VERSION
26
+ MAJOR = 3
27
+ MINOR = 1
28
+ PATCH = 0
29
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
30
+ end
31
+ end
32
+
33
+ def with_file(content)
34
+ Tempfile.open('gettext_i18n_rails_specs') do |f|
35
+ f.write(content)
36
+ f.close
37
+ yield f.path
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nulogy-gettext_i18n_rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 117
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 6
10
+ - 1
11
+ version: 0.4.6.1
12
+ platform: ruby
13
+ authors:
14
+ - Michael Grosser
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-04-05 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: fast_gettext
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email: grosser.michael@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - Rakefile
47
+ - Readme.md
48
+ - VERSION
49
+ - gettext_i18n_rails.gemspec
50
+ - init.rb
51
+ - lib/gettext_i18n_rails.rb
52
+ - lib/gettext_i18n_rails/action_controller.rb
53
+ - lib/gettext_i18n_rails/active_record.rb
54
+ - lib/gettext_i18n_rails/backend.rb
55
+ - lib/gettext_i18n_rails/base_parser.rb
56
+ - lib/gettext_i18n_rails/haml_parser.rb
57
+ - lib/gettext_i18n_rails/hamlet_parser.rb
58
+ - lib/gettext_i18n_rails/html_safe_translations.rb
59
+ - lib/gettext_i18n_rails/i18n_hacks.rb
60
+ - lib/gettext_i18n_rails/model_attributes_finder.rb
61
+ - lib/gettext_i18n_rails/railtie.rb
62
+ - lib/gettext_i18n_rails/ruby_gettext_extractor.rb
63
+ - lib/gettext_i18n_rails/slim_parser.rb
64
+ - lib/gettext_i18n_rails/string_interpolate_fix.rb
65
+ - lib/gettext_i18n_rails/tasks.rb
66
+ - lib/tasks/gettext_rails_i18n.rake
67
+ - spec/gettext_i18n_rails/action_controller_spec.rb
68
+ - spec/gettext_i18n_rails/active_record_spec.rb
69
+ - spec/gettext_i18n_rails/backend_spec.rb
70
+ - spec/gettext_i18n_rails/haml_parser_spec.rb
71
+ - spec/gettext_i18n_rails/hamlet_parser_spec.rb
72
+ - spec/gettext_i18n_rails/slim_parser_spec.rb
73
+ - spec/gettext_i18n_rails/string_interpolate_fix_spec.rb
74
+ - spec/gettext_i18n_rails_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: http://github.com/grosser/gettext_i18n_rails
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.21
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Simple FastGettext Rails integration.
109
+ test_files: []
110
+