Permalink
Browse files

Being able to run 'rake test:plugins' in the application directory

Corrected E9s behaviour within the Rails console
Refactored code and tests a bit
Added TODO's to README.textile
  • Loading branch information...
1 parent 67e0afc commit 6dfb901cb5e8eb8937bb3b08d23a297e29bcddfc Paul Engel committed Jun 25, 2010
View
@@ -45,9 +45,6 @@ Optionally, you can also install the Formtastic plugin:
h2. Usage
-* Add translations within local YML files in /config/locals/
-* Start translating within controllers, models and/or views
-
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -67,7 +64,10 @@ Formtastic (optional)<br>
h2. ToDo's
-* Complete the Dutch pluralization inflections
+* Complete the Dutch inflections
+* Complete README.textile
+* Correct CHANGELOG and VERSION
+* Use the XSS approach for printing internationalized strings
h2. License
View
@@ -5,3 +5,4 @@ module E9s
require "e9s/core"
require "e9s/actionpack"
+require "e9s/engine"
@@ -4,9 +4,9 @@ class Base
def render_with_e9s(*args, &block)
old_value = String.taggify_translations
- if ::E9s::Plugin.taggify_restriction.nil? || (send(::E9s::Plugin.taggify_restriction) rescue nil)
+ if ::E9s::Engine.taggify_restriction.nil? || (send(::E9s::Engine.taggify_restriction) rescue nil)
String.taggify_translations = true
- ::E9s::ActionView.sanitize_html render_without_e9s(*args, &block)
+ ::E9s::Actionpack::ActionView::Sanitizor.sanitize_html render_without_e9s(*args, &block)
else
String.taggify_translations = false
render_without_e9s(*args, &block)
@@ -1,57 +1,59 @@
module E9s
- module ActionView
- module Sanitizor
- extend self
+ module Actionpack
+ module ActionView
+ module Sanitizor
+ extend self
- require "hpricot"
+ require "hpricot"
- def sanitize_html(html)
- return html unless (html || "").include?("<i18n ")
+ def sanitize_html(html)
+ return html unless (html || "").include?("<i18n ")
- doc = Hpricot html
+ doc = Hpricot html
- (doc/"head i18n").each do |i18n|
- i18n.swap i18n.inner_html
- end
+ (doc/"head i18n").each do |i18n|
+ i18n.swap i18n.inner_html
+ end
- (doc/"i18n").each do |i18n|
- elem = Hpricot::Elem.new "span", i18n.raw_attributes.merge({:class => "i18n"})
- elem.inner_html = i18n.inner_html
- i18n.swap elem.to_html
- end
+ (doc/"i18n").each do |i18n|
+ elem = Hpricot::Elem.new "span", i18n.raw_attributes.merge({:class => "i18n"})
+ elem.inner_html = i18n.inner_html
+ i18n.swap elem.to_html
+ end
- (doc/"input").each do |input|
- sanitize_input(input)
- end
+ (doc/"input").each do |input|
+ sanitize_input(input)
+ end
- (doc/"textarea").each do |input|
- sanitize_input(input)
- end
+ (doc/"textarea").each do |input|
+ sanitize_input(input)
+ end
- doc.to_html
- rescue
- html.gsub(/(\<i18n[^\>]+\>)|(\<\/i18n\>)/, "")
- end
+ doc.to_html
+ rescue
+ html.gsub(/(\<i18n[^\>]+\>)|(\<\/i18n\>)/, "")
+ end
- private
+ private
- def sanitize_input(input)
- %w(value seatholder).each do |input_attr|
- next unless input.attributes[input_attr].include?("<i18n ")
+ def sanitize_input(input)
+ %w(value seatholder).each do |input_attr|
+ next unless input.attributes[input_attr].include?("<i18n ")
- i18n = Hpricot(input.attributes[input_attr]).children.first
- i18n.raw_attributes.each do |key, value|
- input.attributes[key] = value
+ i18n = Hpricot(input.attributes[input_attr]).children.first
+ i18n.raw_attributes.each do |key, value|
+ input.attributes[key] = value
+ end
+
+ input.attributes[input_attr] = i18n.inner_html
+ input.attributes["class"] = ["i18n", input.attributes["class"]].uniq.join(" ").strip
end
- input.attributes[input_attr] = i18n.inner_html
- input.attributes["class"] = ["i18n", input.attributes["class"]].uniq.join(" ").strip
+ input
end
-
- input
- end
+ end
end
end
end
@@ -7,10 +7,13 @@ module Internationalization
def self.included(base)
base.cattr_accessor :taggify_translations
base.extend ClassMethods
+ base.send :include, InstanceMethods
end
module ClassMethods
- include InstanceMethods
+ # def something
+ #
+ # end
end
module InstanceMethods
@@ -53,7 +56,7 @@ def t(options = {})
s.cp_case! options[:capitalize] ? default.capitalize : default
end
- String.taggify_translations ? taggify(string, s, key, value) : s
+ taggify_translations ? taggify(string, s, key, value) : s
end.join " "
end
View
@@ -7,9 +7,9 @@ module Engine
def init(test_class = nil)
if test_class
- test_locale = test_class.name.demodulize.downcase.to_sym
+ test_locale = test_class.name.match(/(E9s\:\:Test\:\:Locales\:\:)(\w+)/).captures[1].downcase.to_sym
- I18n.load_path = ["vendor/plugins/e9s/locales/#{test_locale}.yml"]
+ I18n.load_path = [File.join("vendor", "plugins", "e9s", "locales", "#{test_locale}.yml")]
else
I18n.load_path += Dir[Rails.root.join("vendor", "plugins", "e9s", "locales", "*.yml")]
end
@@ -38,3 +38,5 @@ def init(test_class = nil)
end
end
+
+E9s::Engine.init
View
@@ -1,2 +1 @@
-# Include hook code here
require "e9s"
@@ -11,19 +11,19 @@ class InflectionsTest < ActiveSupport::TestCase
end
test "upcase_first" do
- assert_equal "" , "" .upcase_first
- assert_equal "E9s", "e9s".upcase_first
- assert_equal "E9S", "E9S".upcase_first
+ assert_equal "" .upcase_first, ""
+ assert_equal "e9s".upcase_first, "E9s"
+ assert_equal "E9S".upcase_first, "E9S"
end
# test "cp_case" do
# assert true
# end
test "upcase_first!" do
- assert_equal nil , "" .upcase_first!
- assert_equal "E9s", "e9s".upcase_first!
- assert_equal nil , "E9s".upcase_first!
+ assert_equal "" .upcase_first!, nil
+ assert_equal "e9s".upcase_first!, "E9s"
+ assert_equal "E9s".upcase_first!, nil
end
# test "pluralize!" do
View
@@ -9,38 +9,9 @@ class EngineTest < ActiveSupport::TestCase
I18n.locale = ::E9s::Engine.init(Locales::NL)
end
- test "singular_translations" do
- assert_equal "huis" , "house".t
- assert_equal "straat", "street".t
- assert_equal "vraag" , "question".t
- assert_equal "vraag" , "word.question".t
- end
-
- test "plural_translations" do
- assert_equal "huizen" , "houses".t
- assert_equal "straten", "streets".t
- assert_equal "vragen" , "questions".t
- end
-
- test "cased_translations" do
- assert_equal "meer" , "more".t
- assert_equal "Huis" , "House".t
- assert_equal "Straten", "Streets".t
- assert_equal "VRAGEN" , "QUESTIONS".t
- end
-
- test "combined_translations" do
- assert_equal "Meer huizen" , "More houses".t
- assert_equal "MEER STRATEN" , "MORE STREETS".t
- assert_equal "meer vragen" , "more questions".t
- assert_equal "meer vragen" , "more questions".t
- assert_equal "Vragen & Antwoorden", "Questions & Answers".t
- assert_equal "vraag & antwoord" , "question & answer".t
- assert_equal "Vraag & antwoord" , "Question & answer".t
- assert_equal "Man / Vrouw" , "Male / Female".t
- assert_equal "één huis" , "one house".t
- # assert_equal "Één huis" , "One house".t
- end
+ # test "something" do
+ # assert true
+ # end
end
end
View
@@ -1,33 +0,0 @@
-require File.expand_path(File.join(File.dirname(__FILE__), "..", "test_helper.rb"))
-
-module E9s
- module Test
- module Locales
-
- class NL < ActiveSupport::TestCase
- setup do
- include Setup
- I18n.locale = ::E9s::Engine.init(self)
- end
-
- test "dutch_pluralizations" do
- assert_equal "vinnen" , "vin".pl
- assert_equal "tassen" , "tas".pl
- assert_equal "telefoons" , "telefoon".pl
- assert_equal "vragen" , "vraag".pl
- assert_equal "huizen" , "huis".pl
- assert_equal "brieven" , "brief".pl
- assert_equal "broeken" , "broek".pl
- assert_equal "tekens" , "teken".pl
- assert_equal "begrafenissen" , "begrafenis".pl
- assert_equal "diners" , "diner".pl
- assert_equal "jubilea" , "jubileum".pl
- assert_equal "festivals" , "festival".pl
- # assert_equal "vazen" , "vaas".pl
- # assert_equal "vragen & antwoorden", "vraag & antwoord".pl
- end
- end
-
- end
- end
-end
@@ -0,0 +1,35 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "test_helper.rb"))
+
+module E9s
+ module Test
+ module Locales
+ module NL
+
+ class InflectionsTest < ActiveSupport::TestCase
+ setup do
+ include Setup
+ I18n.locale = ::E9s::Engine.init(self)
+ end
+
+ test "dutch_pluralizations" do
+ assert_equal "vinnen" , "vin".pl
+ assert_equal "tassen" , "tas".pl
+ assert_equal "telefoons" , "telefoon".pl
+ assert_equal "vragen" , "vraag".pl
+ assert_equal "huizen" , "huis".pl
+ assert_equal "brieven" , "brief".pl
+ assert_equal "broeken" , "broek".pl
+ assert_equal "tekens" , "teken".pl
+ assert_equal "begrafenissen" , "begrafenis".pl
+ assert_equal "diners" , "diner".pl
+ assert_equal "jubilea" , "jubileum".pl
+ assert_equal "festivals" , "festival".pl
+ # assert_equal "vazen" , "vaas".pl
+ # assert_equal "vragen & antwoorden", "vraag & antwoord".pl
+ end
+ end
+
+ end
+ end
+ end
+end
@@ -0,0 +1,51 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "test_helper.rb"))
+
+module E9s
+ module Test
+ module Locales
+ module NL
+
+ class InternationalizationTest < ActiveSupport::TestCase
+ setup do
+ include Setup
+ I18n.locale = ::E9s::Engine.init(self)
+ end
+
+ test "dutch_singular_translations" do
+ assert_equal "huis" , "house".t
+ assert_equal "straat", "street".t
+ assert_equal "vraag" , "question".t
+ assert_equal "vraag" , "word.question".t
+ end
+
+ test "dutch_plural_translations" do
+ assert_equal "huizen" , "houses".t
+ assert_equal "straten", "streets".t
+ assert_equal "vragen" , "questions".t
+ end
+
+ test "dutch_cased_translations" do
+ assert_equal "meer" , "more".t
+ assert_equal "Huis" , "House".t
+ assert_equal "Straten", "Streets".t
+ assert_equal "VRAGEN" , "QUESTIONS".t
+ end
+
+ test "dutch_combined_translations" do
+ assert_equal "Meer huizen" , "More houses".t
+ assert_equal "MEER STRATEN" , "MORE STREETS".t
+ assert_equal "meer vragen" , "more questions".t
+ assert_equal "meer vragen" , "more questions".t
+ assert_equal "Vragen & Antwoorden", "Questions & Answers".t
+ assert_equal "vraag & antwoord" , "question & answer".t
+ assert_equal "Vraag & antwoord" , "Question & answer".t
+ assert_equal "Man / Vrouw" , "Male / Female".t
+ assert_equal "één huis" , "one house".t
+ # assert_equal "Één huis" , "One house".t
+ end
+ end
+
+ end
+ end
+ end
+end
View
@@ -1,3 +1,5 @@
require "rubygems"
require "active_support"
-require "active_support/test_case"
+require "active_support/test_case"
+
+require File.join(File.dirname(__FILE__), "setup.rb")

0 comments on commit 6dfb901

Please sign in to comment.