form_translation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,3 @@
1
+ module FormTranslation
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'simple_form'
2
+ begin
3
+ require 'nested_form/builder_mixin'
4
+ rescue LoadError
5
+ end
6
+
7
+
8
+ module FormTranslation
9
+ module ViewHelper
10
+ def simple_translated_form_for(object, *args, &block)
11
+ options = args.extract_options!
12
+ simple_form_for(object,
13
+ *(args << options.merge(builder: FormTranslation::CustomFormBuilder)),
14
+ &block)
15
+ end
16
+
17
+ if defined?(FormTranslation::NestedCustomFormBuilder)
18
+ def simple_translated_nested_form_for(object, *args, &block)
19
+ options = args.extract_options!
20
+ simple_nested_form_for(object,
21
+ *(args << options.merge(builder: FormTranslation::NestedCustomFormBuilder)),
22
+ &block)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :form_translation do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
File without changes
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require bootstrap
16
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
14
+
15
+ @import "bootstrap";
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,59 @@
1
+ class ArticlesController < ApplicationController
2
+ before_action :set_article, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /articles
5
+ def index
6
+ @articles = Article.all
7
+ end
8
+
9
+ # GET /articles/1
10
+ def show
11
+ end
12
+
13
+ # GET /articles/new
14
+ def new
15
+ @article = Article.new
16
+ end
17
+
18
+ # GET /articles/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /articles
23
+ def create
24
+ @article = Article.new(article_params)
25
+
26
+ if @article.save
27
+ redirect_to @article, notice: 'Article was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /articles/1
34
+ def update
35
+ if @article.update(article_params)
36
+ redirect_to @article, notice: 'Article was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /articles/1
43
+ def destroy
44
+ @article.destroy
45
+ redirect_to articles_url, notice: 'Article was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_article
51
+ @article = Article.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def article_params
56
+ params.require(:article).permit(:publish_at, :subject, :body, :de_subject,
57
+ :de_body)
58
+ end
59
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ArticlesHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ class Article < ActiveRecord::Base
2
+ include FormTranslation::ForModel
3
+
4
+ translate_me :subject, :body, :publish_at
5
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ <%= simple_translated_form_for(@article) do |f| %>
2
+ <div class="form-inputs">
3
+ <%= f.input :publish_at %>
4
+ </div>
5
+ <div>
6
+ <%= f.languagify do |l| %>
7
+ <%= l.input :subject %>
8
+ <%= l.input :body %>
9
+ <% end %>
10
+ </div>
11
+ <div class="form-actions">
12
+ <%= f.button :submit %>
13
+ </div>
14
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing article</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @article %> |
6
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,31 @@
1
+ <h1>Listing articles</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Publish at</th>
7
+ <th>Subject</th>
8
+ <th>Body</th>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @articles.each do |article| %>
17
+ <tr>
18
+ <td><%= article.publish_at %></td>
19
+ <td><%= article.subject %></td>
20
+ <td><%= article.body %></td>
21
+ <td><%= link_to 'Show', article %></td>
22
+ <td><%= link_to 'Edit', edit_article_path(article) %></td>
23
+ <td><%= link_to 'Destroy', article, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br>
30
+
31
+ <%= link_to 'New Article', new_article_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New article</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,19 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Publish at:</strong>
5
+ <%= @article.publish_at %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Subject:</strong>
10
+ <%= @article.subject %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Body:</strong>
15
+ <%= @article.body %>
16
+ </p>
17
+
18
+ <%= link_to 'Edit', edit_article_path(@article) %> |
19
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "form_translation"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+ config.i18n.enforce_available_locales = true
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ config.i18n.default_locale = :en
21
+ end
22
+ end
23
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000