phrasing 2.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.
- data/.gitignore +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +142 -0
- data/MIT-LICENSE +20 -0
- data/README.md +93 -0
- data/Rakefile +35 -0
- data/app/assets/fonts/icomoon.dev.svg +38 -0
- data/app/assets/fonts/icomoon.eot +0 -0
- data/app/assets/fonts/icomoon.svg +38 -0
- data/app/assets/fonts/icomoon.ttf +0 -0
- data/app/assets/fonts/icomoon.woff +0 -0
- data/app/assets/images/phrasing_information_icon.png +0 -0
- data/app/assets/javascripts/editor.js +318 -0
- data/app/assets/javascripts/head.js +423 -0
- data/app/assets/javascripts/phrasing.js.erb +148 -0
- data/app/assets/javascripts/spin.js +355 -0
- data/app/assets/stylesheets/phrasing.css.scss +240 -0
- data/app/assets/stylesheets/phrasing_edit_mode_bubble.css.scss +117 -0
- data/app/assets/stylesheets/phrasing_engine.css +470 -0
- data/app/assets/stylesheets/phrasing_fonts.css.scss +60 -0
- data/app/controllers/phrasing_phrases_controller.rb +126 -0
- data/app/helpers/inline_helper.rb +47 -0
- data/app/models/phrasing_phrase.rb +97 -0
- data/app/views/layouts/phrasing.html.haml +12 -0
- data/app/views/phrasing/_initializer.html.haml +25 -0
- data/app/views/phrasing/_menu.html.haml +8 -0
- data/app/views/phrasing/_messages.html.haml +4 -0
- data/app/views/phrasing/_production_warning.html.haml +4 -0
- data/app/views/phrasing_phrases/edit.html.haml +7 -0
- data/app/views/phrasing_phrases/help.html.haml +17 -0
- data/app/views/phrasing_phrases/import_export.html.haml +18 -0
- data/app/views/phrasing_phrases/index.html.haml +17 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20120313191745_create_phrasing_phrases.rb +11 -0
- data/lib/phrasing.rb +72 -0
- data/lib/phrasing/ambiguous_phrases_error.rb +3 -0
- data/lib/phrasing/implementation.rb +19 -0
- data/lib/phrasing/phrasable_error_handler.rb +9 -0
- data/lib/phrasing/simple.rb +3 -0
- data/lib/phrasing/version.rb +3 -0
- data/lib/tasks/phrasing_tasks.rake +57 -0
- data/phrasing.gemspec +21 -0
- metadata +135 -0
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
resources Phrasing.route, :as => 'phrasing_phrases', :controller => 'phrasing_phrases', :only => [:index, :edit, :update, :destroy] do
|
3
|
+
collection do
|
4
|
+
get 'help'
|
5
|
+
get 'import_export'
|
6
|
+
get 'sync'
|
7
|
+
get 'download'
|
8
|
+
post 'upload'
|
9
|
+
put 'remote_update_phrase'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/phrasing.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'phrasing'
|
2
|
+
require "phrasing/implementation"
|
3
|
+
require "phrasing/simple"
|
4
|
+
require 'phrasing/phrasable_error_handler'
|
5
|
+
|
6
|
+
module Phrasing
|
7
|
+
module Rails
|
8
|
+
class Engine < ::Rails::Engine
|
9
|
+
initializer :assets, :group => :all do
|
10
|
+
::Rails.application.config.assets.paths << ::Rails.root.join('app', 'assets', 'fonts')
|
11
|
+
::Rails.application.config.assets.paths << ::Rails.root.join('app', 'assets', 'images')
|
12
|
+
::Rails.application.config.assets.precompile += ['editor.js', 'phrasing_engine.css', 'icomoon.dev.svg', 'icomoon.svg', 'icomoon.eot', 'icomoon.ttf', 'icomoon.woff', 'phrasing_information_icon.png']
|
13
|
+
end
|
14
|
+
initializer "phrasing" do
|
15
|
+
ActiveSupport.on_load(:action_controller) do
|
16
|
+
# ActionController::Base.send(:include, PhrasableErrorHandler)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
module Phrasing
|
25
|
+
|
26
|
+
mattr_accessor :allow_update_on_all_models_and_attributes
|
27
|
+
mattr_accessor :route
|
28
|
+
mattr_accessor :everything_is_html_safe
|
29
|
+
mattr_accessor :staging_server_endpoint
|
30
|
+
|
31
|
+
@@route = 'phrasing'
|
32
|
+
@@everything_is_html_safe = false
|
33
|
+
|
34
|
+
def self.setup
|
35
|
+
yield self
|
36
|
+
end
|
37
|
+
|
38
|
+
WHITELIST = "PhrasingPhrase.value"
|
39
|
+
|
40
|
+
def self.whitelist
|
41
|
+
if defined? @@whitelist
|
42
|
+
@@whitelist + [WHITELIST]
|
43
|
+
else
|
44
|
+
[WHITELIST]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.whitelist=(whitelist)
|
49
|
+
@@whitelist = whitelist
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.is_whitelisted?(klass,attribute)
|
53
|
+
allow_update_on_all_models_and_attributes == true or whitelist.include? "#{klass}.#{attribute}"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
module ActionView
|
59
|
+
module Helpers
|
60
|
+
module TranslationHelper
|
61
|
+
private
|
62
|
+
|
63
|
+
def new_html_safe_translation_key?(key)
|
64
|
+
Phrasing.everything_is_html_safe || old_html_safe_translation_key?(key)
|
65
|
+
end
|
66
|
+
|
67
|
+
alias_method :old_html_safe_translation_key?, :html_safe_translation_key?
|
68
|
+
alias_method :html_safe_translation_key?, :new_html_safe_translation_key?
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Phrasing
|
2
|
+
module Implementation
|
3
|
+
# this method overrides part of the i18n gem, lib/i18n/backend/simple.rb
|
4
|
+
def lookup(locale, key, scope = [], options = {})
|
5
|
+
return super unless ActiveRecord::Base.connected? && PhrasingPhrase.table_exists?
|
6
|
+
|
7
|
+
scoped_key = I18n.normalize_keys(nil, key, scope, options[:separator]).join(".")
|
8
|
+
|
9
|
+
cct = PhrasingPhrase.where(locale: locale.to_s, key: scoped_key).first
|
10
|
+
return cct.value if cct
|
11
|
+
|
12
|
+
value = super(locale, key, scope, options)
|
13
|
+
if value.is_a?(String) || value.nil?
|
14
|
+
PhrasingPhrase.create(locale: locale.to_s, key: scoped_key, value: value)
|
15
|
+
end
|
16
|
+
value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
namespace :phrasing do
|
2
|
+
desc "Install the plugin, including the migration."
|
3
|
+
task :install do
|
4
|
+
Rake::Task["phrasing_rails_engine:install:migrations"].invoke
|
5
|
+
Rake::Task["phrasing:install_initializer"].invoke
|
6
|
+
Rake::Task["phrasing:phrasable_creator"].invoke
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Create the initializer file"
|
10
|
+
task :install_initializer do
|
11
|
+
filepath = Rails.root.join *%w(config initializers phrasing.rb)
|
12
|
+
File.open(filepath, 'w') do |f|
|
13
|
+
f << <<-CONFIG
|
14
|
+
Phrasing.setup do |config|
|
15
|
+
config.route = 'phrasing'
|
16
|
+
end
|
17
|
+
|
18
|
+
# List all the model attributes you wish to edit with Phrasing, example:
|
19
|
+
# Phrasing.whitelist = ["Post.title", "Post.description"]
|
20
|
+
Phrasing.whitelist = []
|
21
|
+
# Phrasing.allow_update_on_all_models_and_attributes = true;
|
22
|
+
CONFIG
|
23
|
+
end
|
24
|
+
greenify("You can change the default route and whitelist editable attributes in the phrasing initializer created in the config/intiializers folder.")
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
desc "Create the PhrasingHelper file"
|
29
|
+
task :phrasable_creator do
|
30
|
+
filepath = Rails.root.join *%w(app helpers phrasing_helper.rb)
|
31
|
+
|
32
|
+
File.open(filepath, 'w') do |f|
|
33
|
+
f << <<-MODULE
|
34
|
+
module PhrasingHelper
|
35
|
+
# You must implement the can_edit_phrases? method.
|
36
|
+
# Example:
|
37
|
+
#
|
38
|
+
# def can_edit_phrases?
|
39
|
+
# current_user.is_admin?
|
40
|
+
# end
|
41
|
+
|
42
|
+
def can_edit_phrases?
|
43
|
+
raise NotImplementedError.new("You must implement the can_edit_phrases? method")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
MODULE
|
47
|
+
end
|
48
|
+
greenify("A PhrasingHelper has been created in your app/helper folder. Please implement the can_edit_phrases? method.")
|
49
|
+
greenify("Now run 'rake db:migrate'.")
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def greenify(text)
|
56
|
+
puts "\033[#{32}m#{text}\033[0m"
|
57
|
+
end
|
data/phrasing.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "phrasing/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "phrasing"
|
7
|
+
s.version = Phrasing::VERSION.dup
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.summary = "Edit phrases inline for Rails applications!"
|
10
|
+
s.email = "contact@infinum.co"
|
11
|
+
s.homepage = "http://github.com/infinum/phrasing"
|
12
|
+
s.description = "Phrasing!"
|
13
|
+
s.authors = ['Tomislav Car', 'Damir Svrtan']
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_dependency(%q<rails>, [">= 3.1.0"])
|
19
|
+
s.add_dependency "railties", ">= 3.1"
|
20
|
+
s.add_dependency(%q<haml-rails>)
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phrasing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tomislav Car
|
9
|
+
- Damir Svrtan
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.1.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: railties
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '3.1'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: haml-rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
description: Phrasing!
|
64
|
+
email: contact@infinum.co
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- MIT-LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- app/assets/fonts/icomoon.dev.svg
|
76
|
+
- app/assets/fonts/icomoon.eot
|
77
|
+
- app/assets/fonts/icomoon.svg
|
78
|
+
- app/assets/fonts/icomoon.ttf
|
79
|
+
- app/assets/fonts/icomoon.woff
|
80
|
+
- app/assets/images/phrasing_information_icon.png
|
81
|
+
- app/assets/javascripts/editor.js
|
82
|
+
- app/assets/javascripts/head.js
|
83
|
+
- app/assets/javascripts/phrasing.js.erb
|
84
|
+
- app/assets/javascripts/spin.js
|
85
|
+
- app/assets/stylesheets/phrasing.css.scss
|
86
|
+
- app/assets/stylesheets/phrasing_edit_mode_bubble.css.scss
|
87
|
+
- app/assets/stylesheets/phrasing_engine.css
|
88
|
+
- app/assets/stylesheets/phrasing_fonts.css.scss
|
89
|
+
- app/controllers/phrasing_phrases_controller.rb
|
90
|
+
- app/helpers/inline_helper.rb
|
91
|
+
- app/models/phrasing_phrase.rb
|
92
|
+
- app/views/layouts/phrasing.html.haml
|
93
|
+
- app/views/phrasing/_initializer.html.haml
|
94
|
+
- app/views/phrasing/_menu.html.haml
|
95
|
+
- app/views/phrasing/_messages.html.haml
|
96
|
+
- app/views/phrasing/_production_warning.html.haml
|
97
|
+
- app/views/phrasing_phrases/edit.html.haml
|
98
|
+
- app/views/phrasing_phrases/help.html.haml
|
99
|
+
- app/views/phrasing_phrases/import_export.html.haml
|
100
|
+
- app/views/phrasing_phrases/index.html.haml
|
101
|
+
- config/routes.rb
|
102
|
+
- db/migrate/20120313191745_create_phrasing_phrases.rb
|
103
|
+
- lib/phrasing.rb
|
104
|
+
- lib/phrasing/ambiguous_phrases_error.rb
|
105
|
+
- lib/phrasing/implementation.rb
|
106
|
+
- lib/phrasing/phrasable_error_handler.rb
|
107
|
+
- lib/phrasing/simple.rb
|
108
|
+
- lib/phrasing/version.rb
|
109
|
+
- lib/tasks/phrasing_tasks.rake
|
110
|
+
- phrasing.gemspec
|
111
|
+
homepage: http://github.com/infinum/phrasing
|
112
|
+
licenses: []
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.8.23
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: Edit phrases inline for Rails applications!
|
135
|
+
test_files: []
|