form_translation 0.0.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 (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +22 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +71 -0
  7. data/Rakefile +34 -0
  8. data/app/assets/images/form_translation/.keep +0 -0
  9. data/app/assets/javascripts/form_translation/.keep +0 -0
  10. data/app/assets/stylesheets/form_translation/.keep +0 -0
  11. data/app/controllers/.keep +0 -0
  12. data/app/helpers/.keep +0 -0
  13. data/app/mailers/.keep +0 -0
  14. data/app/models/.keep +0 -0
  15. data/app/views/.keep +0 -0
  16. data/bin/rails +8 -0
  17. data/config/routes.rb +2 -0
  18. data/form_translation.gemspec +26 -0
  19. data/lib/form_translation.rb +26 -0
  20. data/lib/form_translation/active_record.rb +27 -0
  21. data/lib/form_translation/custom_form_builder.rb +22 -0
  22. data/lib/form_translation/engine.rb +10 -0
  23. data/lib/form_translation/errors.rb +5 -0
  24. data/lib/form_translation/for_model.rb +76 -0
  25. data/lib/form_translation/languages_form_builder.rb +73 -0
  26. data/lib/form_translation/version.rb +3 -0
  27. data/lib/form_translation/view_helper.rb +26 -0
  28. data/lib/tasks/form_translation_tasks.rake +4 -0
  29. data/test/dummy/README.rdoc +28 -0
  30. data/test/dummy/Rakefile +6 -0
  31. data/test/dummy/app/assets/images/.keep +0 -0
  32. data/test/dummy/app/assets/javascripts/application.js +16 -0
  33. data/test/dummy/app/assets/javascripts/articles.js +2 -0
  34. data/test/dummy/app/assets/stylesheets/application.css.scss +15 -0
  35. data/test/dummy/app/assets/stylesheets/articles.css +4 -0
  36. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  37. data/test/dummy/app/controllers/application_controller.rb +5 -0
  38. data/test/dummy/app/controllers/articles_controller.rb +59 -0
  39. data/test/dummy/app/controllers/concerns/.keep +0 -0
  40. data/test/dummy/app/helpers/application_helper.rb +2 -0
  41. data/test/dummy/app/helpers/articles_helper.rb +2 -0
  42. data/test/dummy/app/mailers/.keep +0 -0
  43. data/test/dummy/app/models/.keep +0 -0
  44. data/test/dummy/app/models/article.rb +5 -0
  45. data/test/dummy/app/models/concerns/.keep +0 -0
  46. data/test/dummy/app/views/articles/_form.html.erb +14 -0
  47. data/test/dummy/app/views/articles/edit.html.erb +6 -0
  48. data/test/dummy/app/views/articles/index.html.erb +31 -0
  49. data/test/dummy/app/views/articles/new.html.erb +5 -0
  50. data/test/dummy/app/views/articles/show.html.erb +19 -0
  51. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  52. data/test/dummy/bin/bundle +3 -0
  53. data/test/dummy/bin/rails +4 -0
  54. data/test/dummy/bin/rake +4 -0
  55. data/test/dummy/config.ru +4 -0
  56. data/test/dummy/config/application.rb +23 -0
  57. data/test/dummy/config/boot.rb +5 -0
  58. data/test/dummy/config/database.yml +25 -0
  59. data/test/dummy/config/environment.rb +5 -0
  60. data/test/dummy/config/environments/development.rb +31 -0
  61. data/test/dummy/config/environments/production.rb +80 -0
  62. data/test/dummy/config/environments/test.rb +36 -0
  63. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  65. data/test/dummy/config/initializers/form_translation.rb +5 -0
  66. data/test/dummy/config/initializers/inflections.rb +16 -0
  67. data/test/dummy/config/initializers/mime_types.rb +5 -0
  68. data/test/dummy/config/initializers/secret_token.rb +12 -0
  69. data/test/dummy/config/initializers/session_store.rb +3 -0
  70. data/test/dummy/config/initializers/simple_form.rb +161 -0
  71. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  72. data/test/dummy/config/locales/en.yml +23 -0
  73. data/test/dummy/config/locales/simple_form.en.yml +31 -0
  74. data/test/dummy/config/routes.rb +58 -0
  75. data/test/dummy/db/migrate/20140107210825_create_articles.rb +12 -0
  76. data/test/dummy/db/schema.rb +25 -0
  77. data/test/dummy/lib/assets/.keep +0 -0
  78. data/test/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  79. data/test/dummy/log/.keep +0 -0
  80. data/test/dummy/public/404.html +58 -0
  81. data/test/dummy/public/422.html +58 -0
  82. data/test/dummy/public/500.html +57 -0
  83. data/test/dummy/public/favicon.ico +0 -0
  84. data/test/dummy/test/fixtures/articles.yml +11 -0
  85. data/test/dummy/test/helpers/articles_helper_test.rb +4 -0
  86. data/test/dummy/test/models/article_test.rb +7 -0
  87. data/test/form_translation_test.rb +7 -0
  88. data/test/integration/navigation_test.rb +10 -0
  89. data/test/lib/form_translation/active_record_test.rb +12 -0
  90. data/test/lib/form_translation/custom_form_builder_test.rb +117 -0
  91. data/test/test_helper.rb +15 -0
  92. metadata +268 -0
@@ -0,0 +1,58 @@
1
+ Dummy::Application.routes.draw do
2
+ resources :articles
3
+
4
+ # The priority is based upon order of creation: first created -> highest priority.
5
+ # See how all your routes lay out with "rake routes".
6
+
7
+ # You can have the root of your site routed with "root"
8
+ # root 'welcome#index'
9
+
10
+ # Example of regular route:
11
+ # get 'products/:id' => 'catalog#view'
12
+
13
+ # Example of named route that can be invoked with purchase_url(id: product.id)
14
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
15
+
16
+ # Example resource route (maps HTTP verbs to controller actions automatically):
17
+ # resources :products
18
+
19
+ # Example resource route with options:
20
+ # resources :products do
21
+ # member do
22
+ # get 'short'
23
+ # post 'toggle'
24
+ # end
25
+ #
26
+ # collection do
27
+ # get 'sold'
28
+ # end
29
+ # end
30
+
31
+ # Example resource route with sub-resources:
32
+ # resources :products do
33
+ # resources :comments, :sales
34
+ # resource :seller
35
+ # end
36
+
37
+ # Example resource route with more complex sub-resources:
38
+ # resources :products do
39
+ # resources :comments
40
+ # resources :sales do
41
+ # get 'recent', on: :collection
42
+ # end
43
+ # end
44
+
45
+ # Example resource route with concerns:
46
+ # concern :toggleable do
47
+ # post 'toggle'
48
+ # end
49
+ # resources :posts, concerns: :toggleable
50
+ # resources :photos, concerns: :toggleable
51
+
52
+ # Example resource route within a namespace:
53
+ # namespace :admin do
54
+ # # Directs /admin/products/* to Admin::ProductsController
55
+ # # (app/controllers/admin/products_controller.rb)
56
+ # resources :products
57
+ # end
58
+ end
@@ -0,0 +1,12 @@
1
+ class CreateArticles < ActiveRecord::Migration
2
+ def change
3
+ create_table :articles do |t|
4
+ t.datetime :publish_at
5
+ t.string :subject
6
+ t.text :body
7
+ t.text :translation
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20140107210825) do
15
+
16
+ create_table "articles", force: true do |t|
17
+ t.datetime "publish_at"
18
+ t.string "subject"
19
+ t.text "body"
20
+ t.text "translation"
21
+ t.datetime "created_at"
22
+ t.datetime "updated_at"
23
+ end
24
+
25
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%- attributes.each do |attribute| -%>
6
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7
+ <%- end -%>
8
+ </div>
9
+
10
+ <div class="form-actions">
11
+ <%%= f.button :submit %>
12
+ </div>
13
+ <%% end %>
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ publish_at: 2014-01-07 22:08:25
5
+ subject: MyString
6
+ body: MyText
7
+
8
+ two:
9
+ publish_at: 2014-01-07 22:08:25
10
+ subject: MyString
11
+ body: MyText
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class ArticlesHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ArticleTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class FormTranslationTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, FormTranslation
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ class ActiveRecordTest < ActiveSupport::TestCase
4
+
5
+ test "#with_locale" do
6
+ a = Article.create(subject: 'My subject', de_subject: 'Meine Überschrift')
7
+ a.with_locale(:de) do
8
+ assert_equal 'Meine Überschrift', a.subject
9
+ end
10
+ assert_equal 'My subject', a.subject
11
+ end
12
+ end
@@ -0,0 +1,117 @@
1
+ require 'test_helper'
2
+
3
+ class CustomFormBuilderTest < ActiveSupport::TestCase
4
+ setup do
5
+ @template = Object.new
6
+ @template.class.send(:include, ActionView::Context)
7
+ @template.extend ActionView::Helpers::FormHelper
8
+ @template.extend ActionView::Helpers::DateHelper
9
+ @template.extend ActionView::Helpers::FormOptionsHelper
10
+ @template.extend ActionView::Helpers::FormTagHelper
11
+ a = Article.new
12
+ cfb = FormTranslation::CustomFormBuilder.new('article', a, @template, {})
13
+ @p = Proc.new{|form_builder, symbol, options={}| form_builder.input symbol, options}
14
+ @lfb = FormTranslation::LanguagesFormBuilder.new(cfb)
15
+ @template.class.send(:define_method, :controller){ nil }
16
+ @lfb.language = :de
17
+
18
+ end
19
+
20
+ test "creates text input" do
21
+ translated_content = @p.call(@lfb, :subject)
22
+ assert_equal("<div class=\"input string optional article_de_subject\"><label class=\"string optional\" for=\"article_de_subject\">De subject</label><input class=\"string optional\" id=\"article_de_subject\" name=\"article[de_subject]\" type=\"text\" /></div>", translated_content)
23
+ assert_equal translated_content.gsub(/[dD]e[_\s]{1}subject/,'subject'),
24
+ @p.call(@lfb.form_builder, :subject).gsub(/Subject/, 'subject')
25
+ end
26
+
27
+ test "creates checkbox" do
28
+ assert_equal @p.call(@lfb, :subject, as: :boolean).gsub(/[dD]e[_\s]{1}subject/,'subject'),
29
+ @p.call(@lfb.form_builder, :subject, as: :boolean).gsub(/Subject/, 'subject')
30
+ end
31
+
32
+ test "creates email input" do
33
+ assert_equal @p.call(@lfb, :subject, as: :email).gsub(/[dD]e[_\s]{1}subject/,'subject'),
34
+ @p.call(@lfb.form_builder, :subject, as: :email).gsub(/Subject/, 'subject')
35
+ end
36
+
37
+ test "creates url input" do
38
+ assert_equal @p.call(@lfb, :subject, as: :url).gsub(/[dD]e[_\s]{1}subject/,'subject'),
39
+ @p.call(@lfb.form_builder, :subject, as: :url).gsub(/Subject/, 'subject')
40
+ end
41
+
42
+ test "creates tel input" do
43
+ assert_equal @p.call(@lfb, :subject, as: :tel).gsub(/[dD]e[_\s]{1}subject/,'subject'),
44
+ @p.call(@lfb.form_builder, :subject, as: :tel).gsub(/Subject/, 'subject')
45
+ end
46
+
47
+ test "creates password input" do
48
+ assert_equal @p.call(@lfb, :subject, as: :password).gsub(/[dD]e[_\s]{1}subject/,'subject'),
49
+ @p.call(@lfb.form_builder, :subject, as: :password).gsub(/Subject/, 'subject')
50
+ end
51
+
52
+ test "creates search input" do
53
+ assert_equal @p.call(@lfb, :subject, as: :search).gsub(/[dD]e[_\s]{1}subject/,'subject'),
54
+ @p.call(@lfb.form_builder, :subject, as: :search).gsub(/Subject/, 'subject')
55
+ end
56
+
57
+ test "creates textarea" do
58
+ assert_equal @p.call(@lfb, :subject, as: :text).gsub(/[dD]e[_\s]{1}subject/,'subject'),
59
+ @p.call(@lfb.form_builder, :subject, as: :text).gsub(/Subject/, 'subject')
60
+ end
61
+
62
+ test "creates file input" do
63
+ assert_equal @p.call(@lfb, :subject, as: :file).gsub(/[dD]e[_\s]{1}subject/,'subject'),
64
+ @p.call(@lfb.form_builder, :subject, as: :file).gsub(/Subject/, 'subject')
65
+ end
66
+
67
+ test "creates hidden field" do
68
+ assert_equal @p.call(@lfb, :subject, as: :hidden).gsub(/[dD]e[_\s]{1}subject/,'subject'),
69
+ @p.call(@lfb.form_builder, :subject, as: :hidden).gsub(/Subject/, 'subject')
70
+ end
71
+
72
+ test "creates number input" do
73
+ assert_equal @p.call(@lfb, :subject, as: :integer).gsub(/[dD]e[_\s]{1}subject/,'subject'),
74
+ @p.call(@lfb.form_builder, :subject, as: :integer).gsub(/Subject/, 'subject')
75
+
76
+ assert_equal @p.call(@lfb, :subject, as: :float).gsub(/[dD]e[_\s]{1}subject/,'subject'),
77
+ @p.call(@lfb.form_builder, :subject, as: :float).gsub(/Subject/, 'subject')
78
+
79
+ assert_equal @p.call(@lfb, :subject, as: :decimal).gsub(/[dD]e[_\s]{1}subject/,'subject'),
80
+ @p.call(@lfb.form_builder, :subject, as: :decimal).gsub(/Subject/, 'subject')
81
+ end
82
+
83
+ test "creates range input" do
84
+ assert_equal @p.call(@lfb, :subject, as: :range).gsub(/[dD]e[_\s]{1}subject/,'subject'),
85
+ @p.call(@lfb.form_builder, :subject, as: :range).gsub(/Subject/, 'subject')
86
+ end
87
+
88
+ test "creates datetime select" do
89
+ assert_equal @p.call(@lfb, :publish_at, as: :datetime).gsub(/[dD]e[_\s]{1}publish[_\s]{1}at/,'publish_at'),
90
+ @p.call(@lfb.form_builder, :publish_at, as: :datetime).gsub(/Publish at/, 'publish_at')
91
+ end
92
+
93
+ test "creates date select" do
94
+ assert_equal @p.call(@lfb, :publish_at, as: :date).gsub(/[dD]e[_\s]{1}publish[_\s]{1}at/,'publish_at'),
95
+ @p.call(@lfb.form_builder, :publish_at, as: :date).gsub(/Publish at/, 'publish_at')
96
+ end
97
+
98
+ test "creates time select" do
99
+ assert_equal @p.call(@lfb, :publish_at, as: :time).gsub(/[dD]e[_\s]{1}publish[_\s]{1}at/,'publish_at'),
100
+ @p.call(@lfb.form_builder, :publish_at, as: :time).gsub(/Publish at/, 'publish_at')
101
+ end
102
+
103
+ test "creates select" do
104
+ assert_equal @p.call(@lfb, :subject, collection: 10..30).gsub(/[dD]e[_\s]{1}subject/,'subject'),
105
+ @p.call(@lfb.form_builder, :subject, collection: 10..30).gsub(/Subject/, 'subject')
106
+ end
107
+
108
+ test "creates radio buttons" do
109
+ assert_equal @p.call(@lfb, :subject, collection: 10..30, as: :radio_buttons).gsub(/[dD]e[_\s]{1}subject/,'subject'),
110
+ @p.call(@lfb.form_builder, :subject, collection: 10..30, as: :radio_buttons).gsub(/Subject/, 'subject')
111
+ end
112
+
113
+ test "creates checkboxes" do
114
+ assert_equal @p.call(@lfb, :subject, collection: 10..30, as: :check_boxes).gsub(/[dD]e[_\s]{1}subject/,'subject'),
115
+ @p.call(@lfb.form_builder, :subject, collection: 10..30, as: :check_boxes).gsub(/Subject/, 'subject')
116
+ end
117
+ end