whowish_word 0.6.5 → 1.0.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 -2
- data/Gemfile +2 -4
- data/lib/whowish_word/action_controller/base.rb +6 -46
- data/lib/whowish_word/action_view/base.rb +18 -40
- data/lib/whowish_word/backends/defer_to_i18n.rb +18 -0
- data/lib/whowish_word/backends/flat_file_store.rb +75 -0
- data/lib/whowish_word/constant.rb +1 -3
- data/lib/whowish_word/initializer.rb +10 -29
- data/lib/whowish_word/rails/app/controllers/whowish_word_controller.rb +31 -85
- data/lib/whowish_word/whowish_word.rb +3 -6
- data/rails/Gemfile +2 -12
- data/rails/Gemfile.lock +30 -44
- data/rails/app/views/layouts/integration.html.erb +0 -1
- data/rails/config/application.rb +0 -17
- data/rails/config/boot.rb +0 -3
- data/rails/config/environment.rb +0 -9
- data/rails/config/routes.rb +0 -3
- data/rails/spec/controllers/whowish_word_controller_spec.rb +36 -10
- data/rails/spec/features/whowish_word_spec.rb +75 -0
- data/rails/spec/spec_helper.rb +15 -11
- data/rails/spec/support/browser_helper.rb +31 -0
- data/rails/spec/support/json_rspec_helper.rb +0 -3
- data/whowish_word.gemspec +4 -4
- metadata +24 -48
- data/lib/whowish_word/action_mailer/base.rb +0 -7
- data/lib/whowish_word/action_view/template.rb +0 -31
- data/lib/whowish_word/authentication.rb +0 -14
- data/lib/whowish_word/db_migration/active_record/whowish_word_html.rb +0 -15
- data/lib/whowish_word/db_migration/mongoid/whowish_word_html.rb +0 -6
- data/lib/whowish_word/rails/app/models/active_record/whowish_word_html.rb +0 -4
- data/lib/whowish_word/rails/app/models/mongoid/whowish_word_html.rb +0 -9
- data/lib/whowish_word/word_for.rb +0 -94
- data/rails/app/assets/javascripts/home2.js +0 -2
- data/rails/app/assets/javascripts/integration.js +0 -2
- data/rails/app/assets/javascripts/test_javascript.js +0 -2
- data/rails/app/assets/javascripts/test_word_for.js +0 -2
- data/rails/app/assets/stylesheets/home2.css +0 -4
- data/rails/app/assets/stylesheets/integration.css +0 -4
- data/rails/app/assets/stylesheets/test_javascript.css +0 -4
- data/rails/app/assets/stylesheets/test_word_for.css +0 -4
- data/rails/app/controllers/home2_controller.rb +0 -2
- data/rails/app/controllers/test_javascript_controller.rb +0 -11
- data/rails/app/controllers/test_word_for_controller.rb +0 -5
- data/rails/app/helpers/home2_helper.rb +0 -2
- data/rails/app/helpers/test_javascript_helper.rb +0 -2
- data/rails/app/helpers/test_word_for_helper.rb +0 -2
- data/rails/app/views/home2/index.html.erb +0 -2
- data/rails/app/views/home2/test.html.erb +0 -3
- data/rails/app/views/test_javascript/change_value.html.erb +0 -32
- data/rails/app/views/test_javascript/index.html.erb +0 -87
- data/rails/app/views/test_javascript/replace_with_html.html.erb +0 -96
- data/rails/app/views/test_word_for/_partial.html.erb +0 -5
- data/rails/app/views/test_word_for/index.html.erb +0 -9
- data/rails/config/database.yml +0 -25
- data/rails/config/mongoid.rb +0 -6
- data/rails/config/mongoid.yml +0 -14
- data/rails/db/.gitdummy +0 -0
- data/rails/mongo.bat +0 -5
- data/rails/public/jasmine/MIT.LICENSE +0 -20
- data/rails/public/jasmine/jasmine-html.js +0 -190
- data/rails/public/jasmine/jasmine.css +0 -166
- data/rails/public/jasmine/jasmine.js +0 -2476
- data/rails/public/jasmine/jasmine_favicon.png +0 -0
- data/rails/public/javascripts/jquery.loading_button.js +0 -72
- data/rails/public/sinonjs/sinonjs.js +0 -2821
- data/rails/public/test/jquery_version.html +0 -26
- data/rails/spec/integration/whowish_word_spec.rb +0 -102
- data/rails/spec/support/browser.rb +0 -194
- data/spec/spec_helper.rb +0 -19
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
if defined?(ActionController) and defined?(ActionController::Base)
|
2
2
|
class ActionController::Base
|
3
3
|
include WhowishWord::Constant
|
4
|
-
|
4
|
+
|
5
5
|
prepend_before_filter :initialize_whowish_word
|
6
|
-
helper_method :whowish_word
|
6
|
+
helper_method :whowish_word, :whowish_word_active?
|
7
7
|
attr_accessor :whowish_word_config
|
8
8
|
|
9
9
|
def initialize_whowish_word
|
@@ -14,48 +14,8 @@ if defined?(ActionController) and defined?(ActionController::Base)
|
|
14
14
|
return @whowish_word_config
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# s = PREFIX + \
|
21
|
-
# SEPARATOR + \
|
22
|
-
# scope_key_by_partial(uid.to_s) + \
|
23
|
-
# SEPARATOR + \
|
24
|
-
# previous_t(uid)
|
25
|
-
# return "<dfn>#{s}</dfn>".html_safe
|
26
|
-
# else
|
27
|
-
# return previous_t(uid, *variables)
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
|
31
|
-
# def ta(uid, *variables)
|
32
|
-
# if @whowish_word_config.edit_mode == true
|
33
|
-
# s = PREFIX + \
|
34
|
-
# SEPARATOR + \
|
35
|
-
# scope_key_by_partial(uid.to_s) + \
|
36
|
-
# SEPARATOR + \
|
37
|
-
# previous_t(uid)
|
38
|
-
# return s.html_safe
|
39
|
-
# else
|
40
|
-
# return previous_t(uid, *variables)
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
|
44
|
-
# def word_for(namespace, id, *variables)
|
45
|
-
# if @whowish_word_config.edit_mode == true
|
46
|
-
# return WhowishWord.word_for_in_edit_mode(namespace, id, @whowish_word_config.locale, *variables)
|
47
|
-
# else
|
48
|
-
# return WhowishWord.word_for(namespace, id, @whowish_word_config.locale, *variables)
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
|
52
|
-
|
53
|
-
# def word_for_attr(namespace, id, *variables)
|
54
|
-
# if @whowish_word_config.edit_mode == true
|
55
|
-
# return WhowishWord.word_for_attr_in_edit_mode(namespace, id, @whowish_word_config.locale, *variables)
|
56
|
-
# else
|
57
|
-
# return WhowishWord.word_for_attr(namespace, id, @whowish_word_config.locale, *variables)
|
58
|
-
# end
|
59
|
-
# end
|
17
|
+
def whowish_word_active?
|
18
|
+
@whowish_word_config.edit_mode == true
|
19
|
+
end
|
60
20
|
end
|
61
|
-
end
|
21
|
+
end
|
@@ -3,8 +3,8 @@ if defined?(ActionView) and defined?(ActionView::Base)
|
|
3
3
|
include WhowishWord::Constant
|
4
4
|
|
5
5
|
def whowish_word_javascript_and_css(force = false)
|
6
|
-
return "" if
|
7
|
-
|
6
|
+
return "" if !whowish_word_active? and force == false
|
7
|
+
|
8
8
|
script_text = <<-HTML
|
9
9
|
<script type="text/javascript">
|
10
10
|
$w(function() {
|
@@ -12,59 +12,44 @@ if defined?(ActionView) and defined?(ActionView::Base)
|
|
12
12
|
});
|
13
13
|
</script>
|
14
14
|
HTML
|
15
|
-
|
15
|
+
|
16
16
|
return javascript_include_tag("/whowish_word_js").sub('.js', '').html_safe + \
|
17
17
|
stylesheet_link_tag("/whowish_word_css").sub('.css', '').html_safe + \
|
18
18
|
script_text.html_safe
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
# if @whowish_word_config.edit_mode == true
|
23
|
-
# return WhowishWord.word_for_in_edit_mode(namespace, id, @whowish_word_config.locale, *variables)
|
24
|
-
# else
|
25
|
-
# return WhowishWord.word_for(namespace, id, @whowish_word_config.locale, *variables)
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
|
29
|
-
|
30
|
-
# def global_word_for_attr(namespace, id, *variables)
|
31
|
-
# if @whowish_word_config.edit_mode == true
|
32
|
-
# return WhowishWord.word_for_attr_in_edit_mode(namespace, id, @whowish_word_config.locale, *variables)
|
33
|
-
# else
|
34
|
-
# return WhowishWord.word_for_attr(namespace, id, @whowish_word_config.locale, *variables)
|
35
|
-
# end
|
36
|
-
# end
|
21
|
+
alias_method :previous_t, :t
|
37
22
|
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
# end
|
23
|
+
# Translations that are plain-text and outside HTML attributes
|
24
|
+
def t(uid, *variables)
|
25
|
+
return previous_t(uid, *variables) unless whowish_word_active?
|
42
26
|
|
43
|
-
|
44
|
-
# namespace = get_relative_view_path(@whowish_word_page)
|
45
|
-
# global_word_for_attr(namespace, id, *variables)
|
46
|
-
# end
|
27
|
+
translation = previous_t uid
|
47
28
|
|
48
|
-
|
49
|
-
def t(uid, *variables)
|
50
|
-
if @whowish_word_config.edit_mode == true
|
29
|
+
if translation.is_a?(String)
|
51
30
|
s = PREFIX + \
|
52
31
|
SEPARATOR + \
|
53
32
|
scope_key_by_partial(uid.to_s) + \
|
54
33
|
SEPARATOR + \
|
55
|
-
|
34
|
+
translation
|
56
35
|
return "<dfn>#{s}</dfn>".html_safe
|
57
36
|
else
|
58
37
|
return previous_t(uid, *variables)
|
59
38
|
end
|
60
39
|
end
|
61
40
|
|
41
|
+
# Translations that may contain HTML tags and are outside HTML attributes
|
62
42
|
def th(uid, *variables)
|
63
43
|
return t(uid, *variables).html_safe
|
64
44
|
end
|
65
45
|
|
46
|
+
# Translations that are inside HTML attributes (must be plain-text by their definitions)
|
66
47
|
def ta(uid, *variables)
|
67
|
-
|
48
|
+
return previous_t(uid, *variables) unless whowish_word_active?
|
49
|
+
|
50
|
+
translation = previous_t uid
|
51
|
+
|
52
|
+
if translation.is_a?(String)
|
68
53
|
s = PREFIX + \
|
69
54
|
SEPARATOR + \
|
70
55
|
scope_key_by_partial(uid.to_s) + \
|
@@ -75,12 +60,5 @@ if defined?(ActionView) and defined?(ActionView::Base)
|
|
75
60
|
return previous_t(uid, *variables)
|
76
61
|
end
|
77
62
|
end
|
78
|
-
|
79
|
-
|
80
|
-
# private
|
81
|
-
# def get_relative_view_path(full_path)
|
82
|
-
# result = @whowish_word_page.match(/[\/\\](([^\/\\]+)[\/\\]([^\/\\]+))\Z/)
|
83
|
-
# return result[1]
|
84
|
-
# end
|
85
63
|
end
|
86
|
-
end
|
64
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module WhowishWord
|
2
|
+
module Backends
|
3
|
+
class DeferToI18n
|
4
|
+
def initialize
|
5
|
+
end
|
6
|
+
|
7
|
+
def set(key, value)
|
8
|
+
I18n.backend.store_translations(I18n.locale,
|
9
|
+
{ key => value },
|
10
|
+
:escape => false)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(*args)
|
14
|
+
I18n.t *args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module WhowishWord
|
2
|
+
module Backends
|
3
|
+
class FlatFileStore
|
4
|
+
def set(key, value)
|
5
|
+
keys = key.split(".")
|
6
|
+
uid = keys.pop
|
7
|
+
filename = "#{I18n.locale}.yml"
|
8
|
+
|
9
|
+
if keys.length > 1
|
10
|
+
filename = "#{keys[1..-1].join("_")}_#{filename}"
|
11
|
+
end
|
12
|
+
|
13
|
+
paths = [ WhowishWord.config_file_dir ]
|
14
|
+
Rails.logger.debug WhowishWord.config_file_dir
|
15
|
+
paths.push(keys[0]) if keys.length > 0
|
16
|
+
paths.push(filename)
|
17
|
+
|
18
|
+
locale_file = File.join(*paths)
|
19
|
+
FileUtils.mkdir_p(File.join(*paths[0..-2]))
|
20
|
+
|
21
|
+
translation_keys = I18n.normalize_keys(I18n.locale, key, nil, ".")
|
22
|
+
|
23
|
+
file = nil
|
24
|
+
data = {}
|
25
|
+
|
26
|
+
begin
|
27
|
+
if !File.exists?(locale_file)
|
28
|
+
file = File.open(locale_file, 'w', 0777)
|
29
|
+
file.flock(File::LOCK_EX)
|
30
|
+
else
|
31
|
+
file = File.open(locale_file, 'r+', 0777)
|
32
|
+
file.flock(File::LOCK_EX)
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
file.rewind
|
37
|
+
data = YAML.parse(file.read).to_ruby
|
38
|
+
rescue
|
39
|
+
data = {}
|
40
|
+
end
|
41
|
+
|
42
|
+
direct = data
|
43
|
+
translation_keys[0..-2].each { |k|
|
44
|
+
k = k.to_s
|
45
|
+
direct[k] ||= {}
|
46
|
+
direct = direct[k]
|
47
|
+
}
|
48
|
+
|
49
|
+
direct[translation_keys.last.to_s] = value
|
50
|
+
|
51
|
+
file.rewind
|
52
|
+
file.write(YAML.dump(data))
|
53
|
+
file.flush
|
54
|
+
file.truncate(file.pos)
|
55
|
+
ensure
|
56
|
+
file.flock(File::LOCK_UN)
|
57
|
+
file.close
|
58
|
+
end
|
59
|
+
|
60
|
+
direct = I18n.translations
|
61
|
+
translation_keys[0..-2].each { |k|
|
62
|
+
direct[k] ||= {}
|
63
|
+
direct = direct[k]
|
64
|
+
}
|
65
|
+
direct[translation_keys.last] = value
|
66
|
+
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
def get(*args)
|
71
|
+
I18n.t *args
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,54 +1,35 @@
|
|
1
1
|
module WhowishWord
|
2
|
-
|
3
2
|
module Initializer
|
4
|
-
|
5
3
|
def install_route
|
6
|
-
|
7
4
|
Rails.application.routes.prepend do
|
8
|
-
match "whowish_word/change_word", :to=>"whowish_word#change_word"
|
9
|
-
match "whowish_word_css", :to=>"whowish_word#css"
|
10
|
-
match "whowish_word_js", :to=>"whowish_word#js"
|
11
|
-
match "whowish_word/download", :to=>"whowish_word#download"
|
5
|
+
match "whowish_word/change_word", :to => "whowish_word#change_word"
|
6
|
+
match "whowish_word_css", :to => "whowish_word#css"
|
7
|
+
match "whowish_word_js", :to => "whowish_word#js"
|
8
|
+
match "whowish_word/download", :to => "whowish_word#download"
|
12
9
|
end
|
13
|
-
|
14
10
|
end
|
15
11
|
|
16
|
-
# def run_database_migration
|
17
|
-
|
18
|
-
# Dir[File.expand_path("../db_migration/#{@orm_engine}/**/*.rb", __FILE__)].each {|f| require f}
|
19
|
-
|
20
|
-
# end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
12
|
def install_hook
|
25
|
-
|
26
|
-
|
27
|
-
Dir[File.expand_path("../action_mailer/**/*.rb", __FILE__)].each {|f| require f}
|
28
|
-
Dir[File.expand_path("../action_view/**/*.rb", __FILE__)].each {|f| require f}
|
29
|
-
|
13
|
+
require_all("../action_controller/**/*.rb")
|
14
|
+
require_all("../action_view/**/*.rb")
|
30
15
|
end
|
31
16
|
|
32
|
-
|
33
17
|
def load_rails
|
34
|
-
|
35
18
|
paths = ["controllers"]
|
36
19
|
|
37
|
-
# load all controllers, helpers, and models
|
38
20
|
paths.each do |dir|
|
39
|
-
|
40
21
|
path = File.join(File.dirname(__FILE__), 'rails', 'app', dir)
|
41
|
-
|
42
22
|
$LOAD_PATH.insert(0, path)
|
43
23
|
ActiveSupport::Dependencies.autoload_paths.insert(0, path)
|
44
24
|
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
45
|
-
|
46
25
|
end
|
47
26
|
|
48
27
|
ActionController::Base.append_view_path(File.join(File.dirname(__FILE__), 'rails', 'app'))
|
28
|
+
end
|
49
29
|
|
30
|
+
private
|
31
|
+
def require_all(path)
|
32
|
+
Dir[File.expand_path(path, __FILE__)].each { |f| require f }
|
50
33
|
end
|
51
|
-
|
52
34
|
end
|
53
|
-
|
54
35
|
end
|
@@ -1,118 +1,64 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
class WhowishWordController < ApplicationController
|
2
|
+
before_filter do
|
3
|
+
if !whowish_word_active?
|
4
|
+
render :text => 'Not found', :status => 404
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
4
8
|
def css
|
5
9
|
text = ""
|
6
|
-
|
7
|
-
Dir[File.expand_path("../../../public/stylesheets/*.css", __FILE__)].each { |f|
|
10
|
+
|
11
|
+
Dir[File.expand_path("../../../public/stylesheets/*.css", __FILE__)].each { |f|
|
8
12
|
text += IO.read(f)
|
9
13
|
text += "\n\n"
|
10
14
|
}
|
11
|
-
|
15
|
+
|
12
16
|
response.headers["Content-Type"] = "text/css; charset=utf-8"
|
13
17
|
render :text=>text
|
14
18
|
end
|
15
|
-
|
19
|
+
|
16
20
|
def js
|
17
21
|
text = ""
|
18
|
-
|
22
|
+
|
19
23
|
all_files = Dir[File.expand_path("../../../public/javascripts/*.js", __FILE__)]
|
20
24
|
all_files.sort! { |a, b| a <=> b}
|
21
|
-
|
25
|
+
|
22
26
|
all_files.each { |file|
|
23
27
|
text += IO.read(file)
|
24
28
|
text += "\n\n"
|
25
29
|
}
|
26
|
-
|
30
|
+
|
27
31
|
response.headers["Content-Type"] = "text/javascript; charset=utf-8"
|
28
32
|
render :text=>text
|
29
33
|
end
|
30
|
-
|
31
|
-
def change_word
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
filename = "#{I18n.locale}.yml"
|
35
|
+
def change_word
|
36
|
+
store = WhowishWord.backend.new
|
36
37
|
|
37
|
-
if
|
38
|
-
|
38
|
+
if store.set params[:word_id], params[:content]
|
39
|
+
render :json => { :ok => true }
|
40
|
+
else
|
41
|
+
render :json => { :ok => false }, :status => :unprocessable_entity
|
39
42
|
end
|
43
|
+
end
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
paths.push(filename)
|
44
|
-
|
45
|
-
locale_file = File.join(*paths)
|
46
|
-
FileUtils.mkdir_p(File.join(*paths[0..-2]))
|
45
|
+
def download
|
46
|
+
raise 'Not supported'
|
47
47
|
|
48
|
-
translation_keys = I18n.normalize_keys(I18n.locale, params[:word_id], nil, ".")
|
49
|
-
|
50
|
-
file = nil
|
51
|
-
data = {}
|
52
|
-
|
53
48
|
begin
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
file = File.open(locale_file, 'r+', 0777)
|
59
|
-
file.flock(File::LOCK_EX)
|
60
|
-
end
|
61
|
-
|
62
|
-
begin
|
63
|
-
file.rewind
|
64
|
-
data = YAML.parse(file.read).to_ruby
|
65
|
-
rescue
|
66
|
-
data = {}
|
67
|
-
end
|
68
|
-
|
69
|
-
direct = data
|
70
|
-
translation_keys[0..-2].each { |k|
|
71
|
-
k = k.to_s
|
72
|
-
direct[k] ||= {}
|
73
|
-
direct = direct[k]
|
74
|
-
}
|
75
|
-
|
76
|
-
direct[translation_keys.last.to_s] = params[:content]
|
77
|
-
|
78
|
-
file.rewind
|
79
|
-
file.write(YAML.dump(data))
|
80
|
-
file.flush
|
81
|
-
file.truncate(file.pos)
|
82
|
-
ensure
|
83
|
-
file.flock(File::LOCK_UN)
|
84
|
-
file.close
|
49
|
+
require 'zip'
|
50
|
+
rescue Exception => e
|
51
|
+
raise 'Please install the rubyzip gem (version 1.1.0) in order to download whowish_word.zip through the web interface #{e}'
|
85
52
|
end
|
86
53
|
|
87
|
-
|
88
|
-
|
89
|
-
direct[k] ||= {}
|
90
|
-
direct = direct[k]
|
91
|
-
}
|
92
|
-
direct[translation_keys.last] = params[:content]
|
93
|
-
|
94
|
-
render :json=>{
|
95
|
-
:ok => true
|
96
|
-
}
|
97
|
-
end
|
98
|
-
|
99
|
-
def download
|
100
|
-
require 'zip/zip'
|
101
|
-
require 'zip/zipfilesystem'
|
102
|
-
|
103
|
-
t = Tempfile.new("whowish_word.zip")
|
104
|
-
|
105
|
-
Zip::ZipOutputStream.open(t.path) do |zos|
|
54
|
+
zipfile = Tempfile.new("whowish_word.zip")
|
55
|
+
Zip::File.open(zipfile.path, Zip::File::CREATE) do |zipfile|
|
106
56
|
Dir["#{WhowishWord.config_file_dir}/**/*"].each do |file|
|
107
|
-
|
108
|
-
|
109
|
-
zos.put_next_entry("#{file.sub(WhowishWord.config_file_dir + "/", "")}")
|
110
|
-
zos.print IO.read(file)
|
57
|
+
zipfile.add(file.sub(directory, ''), file)
|
111
58
|
end
|
112
59
|
end
|
113
60
|
|
114
|
-
send_file
|
115
|
-
|
116
|
-
t.close
|
61
|
+
send_file zipfile.path, :filename => "whowish_word.zip", :content_type => "application/zip"
|
62
|
+
zipfile.close
|
117
63
|
end
|
118
|
-
end
|
64
|
+
end
|