action_labels 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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +32 -0
- data/lib/action_labels.rb +9 -0
- data/lib/action_labels/active_model_name_extractor.rb +32 -0
- data/lib/action_labels/helper_methods.rb +47 -0
- data/lib/action_labels/locales/da.yml +9 -0
- data/lib/action_labels/locales/en.yml +9 -0
- data/lib/action_labels/locales/sv.yml +9 -0
- data/lib/action_labels/railtie.rb +15 -0
- data/lib/action_labels/version.rb +3 -0
- data/lib/tasks/action_labels_tasks.rake +4 -0
- data/test/action_labels_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +9 -0
- data/test/dummy/app/controllers/application_controller.rb +15 -0
- data/test/dummy/app/controllers/welcome_controller.rb +7 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/article.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/welcome/index.html.erb +52 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/da.yml +6 -0
- data/test/dummy/config/locales/en.yml +27 -0
- data/test/dummy/config/locales/sv.yml +6 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +4126 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/test_helper.rb +15 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: e5fc0be41ecc73d4a5af87061114cb08a483471d
|
4
|
+
data.tar.gz: 50d3186769264727dbb7e9af9f9e0d04a70bd9f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90197540324be2b0fc1180bae19a3f30bc969259c22e7d634dffec41d4a02f629448c61d4cc025ca21c905b0590745f9fd876702c74a9a13ef8e7c9d7515b4d8
|
7
|
+
data.tar.gz: fee0517c63f42a43ae5a243453bd7df92da591f4fce1c9b07a7558f4d6fa8cff4e376656ce775aaa0eac54332ad56150c962cf9d201b81a5b6ad330e52a5629d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
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 = 'ActionLabels'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActionLabels
|
2
|
+
class ActiveModelNameExtractor
|
3
|
+
|
4
|
+
attr_accessor :subject
|
5
|
+
|
6
|
+
def initialize(subject)
|
7
|
+
subject = Array(subject).first
|
8
|
+
|
9
|
+
if subject.nil?
|
10
|
+
raise ArgumentError, "Cannot extract any meaningful name from NilClass"
|
11
|
+
end
|
12
|
+
|
13
|
+
@subject = subject
|
14
|
+
end
|
15
|
+
|
16
|
+
def extract
|
17
|
+
klass = subject.is_a?(Class) ? subject : extract_class
|
18
|
+
klass.model_name
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def extract_class
|
24
|
+
if subject.is_a?(ActiveRecord::Relation)
|
25
|
+
subject.klass
|
26
|
+
else
|
27
|
+
subject.class
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ActionLabels
|
2
|
+
module HelperMethods
|
3
|
+
|
4
|
+
def create_label(subject, count = 1)
|
5
|
+
action_label(:create, subject, count)
|
6
|
+
end
|
7
|
+
|
8
|
+
def edit_label(subject, count = 1)
|
9
|
+
action_label(:edit, subject, count)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show_label(subject, count = 1)
|
13
|
+
action_label(:show, subject, count)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_label(subject, count = 1)
|
17
|
+
action_label(:update, subject, count)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_label(subject, count = 1)
|
21
|
+
action_label(:delete, subject, count)
|
22
|
+
end
|
23
|
+
|
24
|
+
def index_label(subject)
|
25
|
+
action_label(:index, subject, 2)
|
26
|
+
end
|
27
|
+
|
28
|
+
def manage_label(subject)
|
29
|
+
action_label(:manage, subject, 2)
|
30
|
+
end
|
31
|
+
|
32
|
+
def action_label(action, subject, count)
|
33
|
+
am_name = ActiveModelNameExtractor.new(subject).extract
|
34
|
+
subject_name = pluralize_active_model_name(am_name, count)
|
35
|
+
I18n.t("action_labels.#{action}_subject", subject: subject_name, count: count).capitalize
|
36
|
+
end
|
37
|
+
|
38
|
+
def pluralize_active_model_name(model_name, count)
|
39
|
+
model_name.human(count: count)
|
40
|
+
rescue I18n::InvalidPluralizationData
|
41
|
+
model_name.to_s.demodulize.pluralize(count)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
ActionView::Base.send :include, ActionLabels::HelperMethods
|
@@ -0,0 +1,9 @@
|
|
1
|
+
da:
|
2
|
+
action_labels:
|
3
|
+
manage_subject: Håndter %{subject}
|
4
|
+
index_subject: Vis alle %{subject}
|
5
|
+
show_subject: Vis %{subject}
|
6
|
+
create_subject: Opret %{subject}
|
7
|
+
edit_subject: Rediger %{subject}
|
8
|
+
update_subject: Opdater %{subject}
|
9
|
+
delete_subject: Slet %{subject}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
en:
|
2
|
+
action_labels:
|
3
|
+
manage_subject: Manage %{subject}
|
4
|
+
index_subject: Show all %{subject}
|
5
|
+
show_subject: Show %{subject}
|
6
|
+
create_subject: Create %{subject}
|
7
|
+
edit_subject: Edit %{subject}
|
8
|
+
update_subject: Update %{subject}
|
9
|
+
delete_subject: Delete %{subject}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
sv:
|
2
|
+
action_labels:
|
3
|
+
manage_subject: Hantera %{subject}
|
4
|
+
index_subject: Visa alla %{subject}
|
5
|
+
show_subject: Visa %{subject}
|
6
|
+
create_subject: Skapa %{subject}
|
7
|
+
edit_subject: Redigera %{subject}
|
8
|
+
update_subject: Uppdatera %{subject}
|
9
|
+
delete_subject: Radera %{subject}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActionLabels
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
|
4
|
+
initializer 'action_labels' do
|
5
|
+
config.i18n.railties_load_path += paths_to_locales
|
6
|
+
end
|
7
|
+
|
8
|
+
def paths_to_locales
|
9
|
+
action_labels_directory = File.dirname __FILE__
|
10
|
+
Dir.glob(File.join(action_labels_directory, 'locales', '*.yml'))
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -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>.
|
data/test/dummy/Rakefile
ADDED
@@ -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 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_tree .
|
@@ -0,0 +1,15 @@
|
|
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
|
+
before_filter :set_locale
|
6
|
+
|
7
|
+
def set_locale
|
8
|
+
if params[:locale]
|
9
|
+
I18n.locale = params[:locale].to_sym
|
10
|
+
else
|
11
|
+
I18n.locale = I18n.default_locale
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -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,52 @@
|
|
1
|
+
<table class="example-table">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th>Action</th>
|
5
|
+
<th>Localized label</th>
|
6
|
+
</tr>
|
7
|
+
</thead>
|
8
|
+
<tbody>
|
9
|
+
<tr>
|
10
|
+
<td>Manage a collection of articles</td>
|
11
|
+
<td><%= manage_label(Article) %></td>
|
12
|
+
</tr>
|
13
|
+
<tr>
|
14
|
+
<td>Show a list of articles</td>
|
15
|
+
<td><%= index_label(Article.new) %></td>
|
16
|
+
<!--Instances are cool too-->
|
17
|
+
</tr>
|
18
|
+
<tr>
|
19
|
+
<td>Show a particular article</td>
|
20
|
+
<td><%= show_label([Article.new, "this", "does", "not", "matter", "!", "!", 1]) %></td>
|
21
|
+
<!--Even arrays will do - only the first element is used-->
|
22
|
+
</tr>
|
23
|
+
<tr>
|
24
|
+
<td>Create a new article</td>
|
25
|
+
<td><%= create_label(Article) %></td>
|
26
|
+
</tr>
|
27
|
+
<tr>
|
28
|
+
<td>Edit an article</td>
|
29
|
+
<td><%= edit_label(Article) %></td>
|
30
|
+
</tr>
|
31
|
+
<tr>
|
32
|
+
<td>Update an article</td>
|
33
|
+
<td><%= update_label(Article.new) %></td>
|
34
|
+
|
35
|
+
</tr>
|
36
|
+
<tr>
|
37
|
+
<td>Delete an article</td>
|
38
|
+
<td><%= delete_label(Article) %></td>
|
39
|
+
</tr>
|
40
|
+
</tbody>
|
41
|
+
</table>
|
42
|
+
|
43
|
+
<h3>Change locale</h3>
|
44
|
+
<ul>
|
45
|
+
|
46
|
+
<%- I18n.available_locales.each do |locale| %>
|
47
|
+
<li>
|
48
|
+
<a href="?locale=<%= locale %>"><%= locale %></a>
|
49
|
+
</li>
|
50
|
+
<% end %>
|
51
|
+
|
52
|
+
</ul>
|
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "action_labels"
|
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
|
+
|
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 = :da
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|