expat 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bd8d067ee8ca9cc3c5c97e795ba01c3e6783932
4
+ data.tar.gz: b1c676eae7ded7abac302f4457b92c333f467797
5
+ SHA512:
6
+ metadata.gz: a922bd4d6c97643d1855682b53a5acdf15d6f4fe80607c5b55d324b2ed4e0010ea8538302d6d1d11b49cc8c3c4e5e127543551dba50f85aeaaecc95272193e73
7
+ data.tar.gz: 90271a0de80501ea2108b9fcf4d55448029b50bf0ac7cf37d2309bd121c48e9a3050540d1cfcca447c6392e160d4491b4d660e2f71b0c97604c0e00f5d4d77ff
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2016, Ivaldi
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Expat'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/expat .js
2
+ //= link_directory ../stylesheets/expat .css
@@ -0,0 +1,13 @@
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 any plugin's vendor/assets/javascripts directory 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. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module Expat
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require_dependency 'expat/application_controller'
2
+
3
+ module Expat
4
+ class LocalesController < ApplicationController
5
+ def index
6
+ @locales = []
7
+
8
+ Dir.open("#{Rails.root}/config/locales").each do |file|
9
+ unless ['.', '..'].include?(file) || file[0] == '.'
10
+ @locales << file[0...-4] # strip of .yml
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,68 @@
1
+ require_dependency 'expat/application_controller'
2
+
3
+ module Expat
4
+ class TranslationsController < ApplicationController
5
+ before_action :load_translations
6
+
7
+ def index
8
+ end
9
+
10
+ def edit
11
+ @translation = @translations[params[:id]]
12
+ end
13
+
14
+ def update
15
+ @translations[params[:id]] = params[:value]
16
+ redirect_to locale_translations_path(@locale)
17
+ save_translations
18
+ end
19
+
20
+ protected
21
+
22
+ def load_translations
23
+ @locale = params[:locale_id]
24
+ path = "#{Rails.root}/config/locales/#{@locale}.yml"
25
+ yml = YAML.load_file path
26
+ @translations = iterate yml[@locale], ''
27
+ end
28
+
29
+ def save_translations
30
+ path = "#{Rails.root}/config/locales/#{@locale}.yml"
31
+ result = {}
32
+
33
+ @translations.each do |key, value|
34
+ key_parts = key.split('.')
35
+
36
+ current = result
37
+ last_key = nil
38
+ level = 0
39
+ key_parts.each do |part|
40
+ unless current[part].present?
41
+ current[part] = {}
42
+ end
43
+ if level < key_parts.count - 1
44
+ current = current[part]
45
+ else
46
+ last_key = part
47
+ end
48
+ level += 1
49
+ end
50
+ current[last_key] = value
51
+ end
52
+
53
+ File.write path, { @locale => result }.to_yaml
54
+ end
55
+
56
+ def iterate node, parent, result = {}
57
+ node.each do |k,v|
58
+ if v.respond_to? :each
59
+ iterate node[k], "#{parent}#{k}.", result
60
+ else
61
+ result["#{parent}#{k}"] = v
62
+ end
63
+ end
64
+
65
+ result
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,4 @@
1
+ module Expat
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Expat
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Expat
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Expat
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ <ul>
2
+ <% @locales.each do |locale| %>
3
+ <li><%= link_to locale.upcase, locale_translations_path(locale) %></li>
4
+ <% end %>
5
+ </ul>
@@ -0,0 +1,5 @@
1
+ <%= form_tag locale_translation_path, method: :patch do |f| %>
2
+ <%= label_tag :value, params[:id] %>
3
+ <%= text_field_tag :value, @translation %>
4
+ <input type="submit" value="save" />
5
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,13 @@
1
+ <table>
2
+ <% @translations.each do |key, value| %>
3
+ <tr>
4
+ <td>
5
+ <%= key %>
6
+ </td>
7
+ <td>
8
+ <%= link_to value, edit_locale_translation_path(
9
+ locale_id: @locale, id: key) %>
10
+ </td>
11
+ </tr>
12
+ <% end %>
13
+ </table>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Expat</title>
5
+ <%= stylesheet_link_tag "expat/application", media: "all" %>
6
+ <%= javascript_include_tag "expat/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Expat::Engine.routes.draw do
2
+ root 'locales#index'
3
+
4
+ resources :locales, only: [] do
5
+ resources :translations, id: /[^\/]+/
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Expat
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Expat
4
+ end
5
+ end
data/lib/expat.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "expat/engine"
2
+
3
+ module Expat
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :expat do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: expat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frank Groeneveld
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ description: Expat adds a mountable web application to your development environment
48
+ that will enable you to manage the i18n yaml files of your Rails application.
49
+ email:
50
+ - frank@ivaldi.nl
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - LICENSE
56
+ - Rakefile
57
+ - app/assets/config/expat_manifest.js
58
+ - app/assets/javascripts/expat/application.js
59
+ - app/assets/stylesheets/expat/application.css
60
+ - app/controllers/expat/application_controller.rb
61
+ - app/controllers/expat/locales_controller.rb
62
+ - app/controllers/expat/translations_controller.rb
63
+ - app/helpers/expat/application_helper.rb
64
+ - app/jobs/expat/application_job.rb
65
+ - app/mailers/expat/application_mailer.rb
66
+ - app/models/expat/application_record.rb
67
+ - app/views/expat/locales/index.html.erb
68
+ - app/views/expat/translations/_form.html.erb
69
+ - app/views/expat/translations/edit.html.erb
70
+ - app/views/expat/translations/index.html.erb
71
+ - app/views/layouts/expat/application.html.erb
72
+ - config/routes.rb
73
+ - lib/expat.rb
74
+ - lib/expat/engine.rb
75
+ - lib/tasks/expat_tasks.rake
76
+ homepage: https://github.com/ivaldi/expat/
77
+ licenses:
78
+ - BSD-2-Clause
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Manage your i18n yaml files using a simple web interface
100
+ test_files: []