whowish_word 0.3.3 → 0.4.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 +3 -1
- data/.project +0 -1
- data/README.md +20 -26
- data/lib/whowish_word/action_controller/base.rb +15 -29
- data/lib/whowish_word/action_mailer/base.rb +3 -8
- data/lib/whowish_word/action_view/base.rb +52 -41
- data/lib/whowish_word/action_view/template.rb +18 -18
- data/lib/whowish_word/authentication.rb +9 -9
- data/lib/whowish_word/config.rb +1 -10
- data/lib/whowish_word/db_migration/active_record/whowish_word_html.rb +10 -10
- data/lib/whowish_word/db_migration/mongoid/whowish_word_html.rb +5 -5
- data/lib/whowish_word/initializer.rb +4 -4
- data/lib/whowish_word/rails/app/controllers/whowish_word_controller.rb +35 -26
- data/lib/whowish_word/rails/app/models/active_record/whowish_word_html.rb +2 -2
- data/lib/whowish_word/rails/app/models/mongoid/whowish_word_html.rb +6 -6
- data/lib/whowish_word/whowish_word.rb +17 -18
- data/rails/Gemfile +1 -2
- data/rails/Gemfile.lock +77 -75
- data/rails/app/assets/javascripts/home2.js +2 -0
- data/rails/app/assets/stylesheets/home2.css +4 -0
- data/rails/app/controllers/application_controller.rb +1 -1
- data/rails/app/controllers/home2_controller.rb +2 -0
- data/rails/app/helpers/home2_helper.rb +2 -0
- data/rails/app/views/home/index.html.erb +31 -30
- data/rails/app/views/home2/index.html.erb +4 -0
- data/rails/app/views/integration/attr.html.erb +1 -1
- data/rails/app/views/integration/index.html.erb +1 -1
- data/rails/app/views/integration/select.html.erb +1 -1
- data/rails/app/views/integration/value.html.erb +1 -1
- data/rails/config/application.rb +0 -2
- data/rails/config/initializers/whowish_word.rb +1 -1
- data/rails/config/locales/whowish_word/en.yml +4 -0
- data/rails/config/locales/whowish_word/jp.yml +4 -0
- data/rails/config/locales/whowish_word/th.yml +4 -0
- data/rails/spec/controllers/whowish_word_controller_spec.rb +2 -39
- data/rails/spec/integration/whowish_word_spec.rb +1 -16
- data/rails/spec/spec_helper.rb +1 -11
- data/spec/spec_helper.rb +2 -0
- data/whowish_word.gemspec +2 -2
- metadata +13 -81
- data/ISSUE.md +0 -93
- data/rails/spec/integration/whowish_word_generator_spec.rb +0 -140
- data/rails/spec/support/mongoid_helper.rb +0 -10
- data/spec/unit/word_for_attr_in_edit_mode_spec.rb +0 -44
- data/spec/unit/word_for_attr_spec.rb +0 -44
- data/spec/unit/word_for_in_edit_mode_spec.rb +0 -44
- data/spec/unit/word_for_spec.rb +0 -44
data/.gitignore
CHANGED
data/.project
CHANGED
data/README.md
CHANGED
@@ -31,19 +31,19 @@ Demo: http://whowish-word.heroku.com
|
|
31
31
|
How you should work
|
32
32
|
-------------------
|
33
33
|
|
34
|
-
In your view, e.g. index.html.erb, use
|
34
|
+
In your view, e.g. index.html.erb, use t(:identifier) and ta(:identifier):
|
35
35
|
|
36
36
|
```erb
|
37
|
-
<h1><%=
|
38
|
-
<h3><%=
|
37
|
+
<h1><%=t :title%></h1>
|
38
|
+
<h3><%=t :you_are_here_for_number_of_times, :number=> 10 %></h3>
|
39
39
|
|
40
|
-
<b><%=
|
40
|
+
<b><%=t :name_label%><b> <%=t :my_name%><br/>
|
41
41
|
|
42
|
-
<b><%=
|
43
|
-
<input type="text" placeholder="<%=
|
44
|
-
<a href="#" title="<%=
|
42
|
+
<b><%=t :your_name_label%></b>
|
43
|
+
<input type="text" placeholder="<%=ta :your_name_here%>"><br/>
|
44
|
+
<a href="#" title="<%=ta :your_name_will_be_kept_secret%>">?</a>
|
45
45
|
|
46
|
-
<button><%=
|
46
|
+
<button><%=ta :submit_button%></button>
|
47
47
|
```
|
48
48
|
|
49
49
|
Now when you want to edit wording:
|
@@ -71,13 +71,13 @@ Demo: http://whowish-word.heroku.com
|
|
71
71
|
WhowishWord supports variables:
|
72
72
|
|
73
73
|
```erb
|
74
|
-
<%=
|
74
|
+
<%=t :you_are_here_for_number_of_times, :number=> 10 %>
|
75
75
|
```
|
76
76
|
|
77
77
|
If you set the word :you_are_here_for_number_of_times to be
|
78
78
|
|
79
79
|
```
|
80
|
-
You are here {number} times already
|
80
|
+
You are here %{number} times already
|
81
81
|
```
|
82
82
|
|
83
83
|
WhowishWord renders it as:
|
@@ -92,7 +92,7 @@ Multi-language support
|
|
92
92
|
You can change locale of WhowishWord by:
|
93
93
|
|
94
94
|
```ruby
|
95
|
-
|
95
|
+
I18n.locale = :en
|
96
96
|
```
|
97
97
|
|
98
98
|
In Rails, you should add before_filter in the application controller as shown below:
|
@@ -106,7 +106,7 @@ def set_locale
|
|
106
106
|
end
|
107
107
|
|
108
108
|
session[:locale] ||= "en"
|
109
|
-
|
109
|
+
I18n.locale = session[:locale].to_sym
|
110
110
|
end
|
111
111
|
```
|
112
112
|
|
@@ -114,7 +114,7 @@ end
|
|
114
114
|
Prerequisite
|
115
115
|
-------------------
|
116
116
|
|
117
|
-
Rails 3.
|
117
|
+
Rails 3.2.3
|
118
118
|
|
119
119
|
It does not work with Rails 3.0.*, yet. Please send me an issue and I will fix it. (I'm just lazy)
|
120
120
|
|
@@ -123,7 +123,7 @@ It does not work with Rails 3.0.*, yet. Please send me an issue and I will fix i
|
|
123
123
|
How to use it
|
124
124
|
-------------------
|
125
125
|
|
126
|
-
|
126
|
+
1. Install it:
|
127
127
|
```
|
128
128
|
gem install whowish_word
|
129
129
|
```
|
@@ -133,17 +133,15 @@ Or, in your Gemfile, put in the below line:
|
|
133
133
|
gem 'whowish_word'
|
134
134
|
```
|
135
135
|
|
136
|
-
|
136
|
+
2. Create ```RAILS_ROOT/config/initializers/whowish_word.rb``` that contains:
|
137
137
|
|
138
138
|
```ruby
|
139
139
|
require 'whowish_word'
|
140
140
|
|
141
|
-
WhowishWord.init(
|
141
|
+
WhowishWord.init()
|
142
142
|
|
143
143
|
```
|
144
144
|
|
145
|
-
You can use either use :active_record or :mongoid
|
146
|
-
|
147
145
|
And, in your layout, please drop this line inside the tag header:
|
148
146
|
|
149
147
|
```erb
|
@@ -152,11 +150,12 @@ And, in your layout, please drop this line inside the tag header:
|
|
152
150
|
|
153
151
|
It is to include the required Javascript and css files, when the edit mode is activated.
|
154
152
|
|
153
|
+
3. When deploying, please create a folder ```RAILS_ROOT/config/locales/whowish_word``` and make it a shared path.
|
155
154
|
|
156
|
-
|
157
|
-
|
155
|
+
All edited words will be generated in this folder.
|
156
|
+
|
157
|
+
Please also make the folder writable.
|
158
158
|
|
159
|
-
It is fast because words are kept in memory. They are not kept in database while your Rails is running.
|
160
159
|
|
161
160
|
|
162
161
|
Help me
|
@@ -164,10 +163,6 @@ Help me
|
|
164
163
|
|
165
164
|
1. Fork the project
|
166
165
|
* Run all tests first:
|
167
|
-
* Go to ROOT, type
|
168
|
-
```
|
169
|
-
bundle exec rspec spec/*
|
170
|
-
```
|
171
166
|
* Go to ROOT/rails, type
|
172
167
|
```
|
173
168
|
bundle exec rspec spec/*
|
@@ -184,7 +179,6 @@ Authors
|
|
184
179
|
-------------------
|
185
180
|
|
186
181
|
Tanin Na Nakorn
|
187
|
-
|
188
182
|
Tanun Niyomjit (Designer)
|
189
183
|
|
190
184
|
|
@@ -1,46 +1,32 @@
|
|
1
|
-
|
2
1
|
if defined?(ActionController) and defined?(ActionController::Base)
|
3
|
-
|
4
2
|
class ActionController::Base
|
5
|
-
|
6
3
|
prepend_before_filter :initialize_whowish_word
|
4
|
+
helper_method :whowish_word
|
7
5
|
attr_accessor :whowish_word_config
|
8
6
|
|
9
|
-
|
10
7
|
def initialize_whowish_word
|
11
8
|
@whowish_word_config = WhowishWord::Config.new
|
12
|
-
$whowish_word_config = @whowish_word_config
|
13
9
|
end
|
14
10
|
|
15
|
-
|
16
|
-
helper_method :whowish_word
|
17
|
-
|
18
11
|
def whowish_word
|
19
12
|
return @whowish_word_config
|
20
13
|
end
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
15
|
+
# def word_for(namespace, id, *variables)
|
16
|
+
# if @whowish_word_config.edit_mode == true
|
17
|
+
# return WhowishWord.word_for_in_edit_mode(namespace, id, @whowish_word_config.locale, *variables)
|
18
|
+
# else
|
19
|
+
# return WhowishWord.word_for(namespace, id, @whowish_word_config.locale, *variables)
|
20
|
+
# end
|
21
|
+
# end
|
32
22
|
|
33
23
|
|
34
|
-
def word_for_attr(namespace, id, *variables)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
24
|
+
# def word_for_attr(namespace, id, *variables)
|
25
|
+
# if @whowish_word_config.edit_mode == true
|
26
|
+
# return WhowishWord.word_for_attr_in_edit_mode(namespace, id, @whowish_word_config.locale, *variables)
|
27
|
+
# else
|
28
|
+
# return WhowishWord.word_for_attr(namespace, id, @whowish_word_config.locale, *variables)
|
29
|
+
# end
|
30
|
+
# end
|
44
31
|
end
|
45
|
-
|
46
32
|
end
|
@@ -1,12 +1,7 @@
|
|
1
|
-
|
2
1
|
if defined?(ActionMailer) and defined?(ActionMailer::Base)
|
3
|
-
|
4
2
|
class ActionMailer::Base
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
3
|
+
# def word_for(id, *p)
|
4
|
+
# WhowishWord.word_for(mailer_name + "/" + @template+".html.erb",id,*p)
|
5
|
+
# end
|
10
6
|
end
|
11
|
-
|
12
7
|
end
|
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
1
|
if defined?(ActionView) and defined?(ActionView::Base)
|
3
|
-
|
4
2
|
class ActionView::Base
|
5
|
-
|
3
|
+
include WhowishWord::Constant
|
6
4
|
|
7
5
|
def whowish_word_javascript_and_css(force = false)
|
8
|
-
|
9
6
|
return "" if @whowish_word_config.edit_mode != true and force == false
|
10
7
|
|
11
8
|
script_text = <<-HTML
|
@@ -16,56 +13,70 @@ if defined?(ActionView) and defined?(ActionView::Base)
|
|
16
13
|
</script>
|
17
14
|
HTML
|
18
15
|
|
19
|
-
return "
|
20
|
-
|
16
|
+
return javascript_include_tag("/whowish_word_js").sub('.js', '').html_safe + \
|
17
|
+
stylesheet_link_tag("/whowish_word_css").sub('.css', '').html_safe + \
|
21
18
|
script_text.html_safe
|
22
19
|
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
# def global_word_for(namespace, id, *variables)
|
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
|
37
|
+
|
38
|
+
# def word_for(id, *variables)
|
39
|
+
# namespace = get_relative_view_path(@whowish_word_page)
|
40
|
+
# global_word_for(namespace, id, *variables)
|
41
|
+
# end
|
42
|
+
|
43
|
+
# def word_for_attr(id, *variables)
|
44
|
+
# namespace = get_relative_view_path(@whowish_word_page)
|
45
|
+
# global_word_for_attr(namespace, id, *variables)
|
46
|
+
# end
|
47
|
+
|
48
|
+
alias_method :previous_t, :t
|
49
|
+
def t(uid, *variables)
|
27
50
|
if @whowish_word_config.edit_mode == true
|
28
|
-
|
51
|
+
s = PREFIX + \
|
52
|
+
SEPARATOR + \
|
53
|
+
uid.to_s + \
|
54
|
+
SEPARATOR + \
|
55
|
+
previous_t(uid, *variables)
|
56
|
+
return "<dfn>#{s}</dfn>".html_safe
|
29
57
|
else
|
30
|
-
return
|
58
|
+
return previous_t(uid, *variables)
|
31
59
|
end
|
32
|
-
|
33
60
|
end
|
34
61
|
|
35
|
-
|
36
|
-
def global_word_for_attr(namespace, id, *variables)
|
37
|
-
|
62
|
+
def ta(uid, *variables)
|
38
63
|
if @whowish_word_config.edit_mode == true
|
39
|
-
|
64
|
+
s = PREFIX + \
|
65
|
+
SEPARATOR + \
|
66
|
+
uid.to_s + \
|
67
|
+
SEPARATOR + \
|
68
|
+
previous_t(uid, *variables)
|
69
|
+
return s.html_safe
|
40
70
|
else
|
41
|
-
return
|
71
|
+
return previous_t(uid, *variables)
|
42
72
|
end
|
43
|
-
|
44
73
|
end
|
45
74
|
|
46
75
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
def word_for_attr(id, *variables)
|
56
|
-
|
57
|
-
namespace = get_relative_view_path(@whowish_word_page)
|
58
|
-
global_word_for_attr(namespace, id, *variables)
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
private
|
64
|
-
def get_relative_view_path(full_path)
|
65
|
-
result = @whowish_word_page.match(/[\/\\](([^\/\\]+)[\/\\]([^\/\\]+))\Z/)
|
66
|
-
return result[1]
|
67
|
-
end
|
68
|
-
|
76
|
+
# private
|
77
|
+
# def get_relative_view_path(full_path)
|
78
|
+
# result = @whowish_word_page.match(/[\/\\](([^\/\\]+)[\/\\]([^\/\\]+))\Z/)
|
79
|
+
# return result[1]
|
80
|
+
# end
|
69
81
|
end
|
70
|
-
|
71
82
|
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
|
2
|
-
if defined?(ActionView) and defined?(ActionView::Base)
|
2
|
+
# if defined?(ActionView) and defined?(ActionView::Base)
|
3
3
|
|
4
|
-
|
4
|
+
# class ActionView::Template
|
5
5
|
|
6
|
-
|
6
|
+
# alias_method :render_original, :render
|
7
7
|
|
8
|
-
|
8
|
+
# def render(view, locals, buffer=nil, &block)
|
9
9
|
|
10
|
-
|
10
|
+
# previous_whowish_word_page = nil
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# if view.instance_variable_defined?(:@whowish_word_page)
|
13
|
+
# previous_whowish_word_page = view.instance_variable_get(:@whowish_word_page)
|
14
|
+
# end
|
15
15
|
|
16
|
-
|
16
|
+
# view.instance_variable_set(:@whowish_word_page, @identifier)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
# if view.controller.respond_to?(:whowish_word_edit_mode)
|
19
|
+
# view.instance_variable_set(:@whowish_word_edit_mode, view.controller.whowish_word_edit_mode)
|
20
|
+
# end
|
21
21
|
|
22
|
-
|
22
|
+
# html = render_original(view, locals, buffer, &block)
|
23
23
|
|
24
|
-
|
24
|
+
# view.instance_variable_set(:@whowish_word_page, previous_whowish_word_page)
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
# return html
|
27
|
+
# end
|
28
28
|
|
29
|
-
|
29
|
+
# end
|
30
30
|
|
31
|
-
end
|
31
|
+
# end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module WhowishWord
|
1
|
+
# module WhowishWord
|
2
2
|
|
3
|
-
|
3
|
+
# module Authentication
|
4
4
|
|
5
|
-
|
5
|
+
# attr_accessor :username, :password
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
# def init_username_and_password
|
8
|
+
# @username ||= "whowishword"
|
9
|
+
# @password ||= "pass"
|
10
|
+
# end
|
11
11
|
|
12
|
-
|
12
|
+
# end
|
13
13
|
|
14
|
-
end
|
14
|
+
# end
|
data/lib/whowish_word/config.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
module WhowishWord
|
2
|
-
|
3
2
|
class Config
|
4
|
-
|
5
|
-
attr_accessor :locale, :edit_mode
|
3
|
+
attr_accessor :edit_mode
|
6
4
|
|
7
5
|
def initialize
|
8
|
-
@locale = "en"
|
9
6
|
@edit_mode = false
|
10
7
|
end
|
11
8
|
|
12
9
|
def activate_edit_mode
|
13
10
|
@edit_mode = true
|
14
11
|
end
|
15
|
-
|
16
|
-
def set_locale(locale)
|
17
|
-
@locale = locale
|
18
|
-
end
|
19
|
-
|
20
12
|
end
|
21
|
-
|
22
13
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
begin
|
2
|
-
|
1
|
+
# begin
|
2
|
+
# ActiveRecord::Schema.define do
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
# create_table "whowish_word_htmls", :force => false do |t|
|
5
|
+
# t.string "word_id", :null => false
|
6
|
+
# t.text "content", :null => false
|
7
|
+
# end
|
8
8
|
|
9
|
-
|
9
|
+
# add_index :whowish_word_htmls, :word_id, :unique => true
|
10
10
|
|
11
|
-
|
11
|
+
# end
|
12
12
|
|
13
|
-
rescue Exception=>e
|
13
|
+
# rescue Exception=>e
|
14
14
|
|
15
|
-
end
|
15
|
+
# end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
begin
|
2
|
-
|
3
|
-
|
4
|
-
rescue Exception=>e
|
1
|
+
# begin
|
2
|
+
# WhowishWordHtml.collection.drop_indexes
|
3
|
+
# WhowishWordHtml.create_indexes
|
4
|
+
# rescue Exception=>e
|
5
5
|
|
6
|
-
end
|
6
|
+
# end
|
@@ -12,11 +12,11 @@ module WhowishWord
|
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
-
def run_database_migration
|
15
|
+
# def run_database_migration
|
16
16
|
|
17
|
-
|
17
|
+
# Dir[File.expand_path("../db_migration/#{@orm_engine}/**/*.rb", __FILE__)].each {|f| require f}
|
18
18
|
|
19
|
-
end
|
19
|
+
# end
|
20
20
|
|
21
21
|
|
22
22
|
|
@@ -31,7 +31,7 @@ module WhowishWord
|
|
31
31
|
|
32
32
|
def load_rails
|
33
33
|
|
34
|
-
paths = ["controllers"
|
34
|
+
paths = ["controllers"]
|
35
35
|
|
36
36
|
# load all controllers, helpers, and models
|
37
37
|
paths.each do |dir|
|
@@ -1,7 +1,5 @@
|
|
1
|
-
class WhowishWordController <
|
2
|
-
|
1
|
+
class WhowishWordController < ApplicationController
|
3
2
|
def css
|
4
|
-
|
5
3
|
text = ""
|
6
4
|
|
7
5
|
Dir[File.expand_path("../../../public/stylesheets/*.css", __FILE__)].each { |f|
|
@@ -11,11 +9,9 @@ class WhowishWordController < ActionController::Base
|
|
11
9
|
|
12
10
|
response.headers["Content-Type"] = "text/css; charset=utf-8"
|
13
11
|
render :text=>text
|
14
|
-
|
15
12
|
end
|
16
13
|
|
17
14
|
def js
|
18
|
-
|
19
15
|
text = ""
|
20
16
|
|
21
17
|
all_files = Dir[File.expand_path("../../../public/javascripts/*.js", __FILE__)]
|
@@ -28,34 +24,47 @@ class WhowishWordController < ActionController::Base
|
|
28
24
|
|
29
25
|
response.headers["Content-Type"] = "text/javascript; charset=utf-8"
|
30
26
|
render :text=>text
|
31
|
-
|
32
27
|
end
|
33
28
|
|
34
29
|
def change_word
|
30
|
+
locale_file = File.join(Rails.root, "config", "locales", "whowish_word", "#{I18n.locale}.yml")
|
31
|
+
|
32
|
+
file = nil
|
33
|
+
data = {}
|
34
|
+
|
35
|
+
begin
|
36
|
+
if !File.exists?(locale_file)
|
37
|
+
file = File.open(locale_file, 'w', 0777)
|
38
|
+
file.flock(File::LOCK_EX)
|
39
|
+
else
|
40
|
+
file = File.open(locale_file, 'r+', 0777)
|
41
|
+
file.flock(File::LOCK_EX)
|
42
|
+
end
|
35
43
|
|
36
|
-
|
44
|
+
begin
|
45
|
+
file.rewind
|
46
|
+
data = YAML.parse(file.read).to_ruby
|
47
|
+
rescue
|
48
|
+
data = {}
|
49
|
+
end
|
37
50
|
|
38
|
-
|
51
|
+
data[I18n.locale.to_s] ||= {}
|
52
|
+
data[I18n.locale.to_s][params[:word_id]] = params[:content]
|
39
53
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
"- Someone else changed the word at the very same time<br/>" + \
|
48
|
-
"- Database connection failed<br/>" + \
|
49
|
-
"By all means, please try again.<br/>"
|
50
|
-
|
51
|
-
render :json=>{:ok=>false,:error_message=>error_message}
|
52
|
-
|
54
|
+
file.rewind
|
55
|
+
file.write(YAML.dump(data))
|
56
|
+
file.flush
|
57
|
+
file.truncate(file.pos)
|
58
|
+
ensure
|
59
|
+
file.flock(File::LOCK_UN)
|
60
|
+
file.close
|
53
61
|
end
|
62
|
+
|
63
|
+
I18n.translations[I18n.locale.to_sym] ||= {}
|
64
|
+
I18n.translations[I18n.locale.to_sym][params[:word_id].to_sym] = params[:content]
|
54
65
|
|
55
|
-
|
56
|
-
|
57
|
-
|
66
|
+
render :json=>{
|
67
|
+
:ok => true
|
68
|
+
}
|
58
69
|
end
|
59
|
-
|
60
|
-
|
61
70
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class WhowishWordHtml
|
2
|
-
|
1
|
+
# class WhowishWordHtml
|
2
|
+
# include Mongoid::Document
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
# field :word_id,:type=>String
|
5
|
+
# field :content, :type=>String
|
6
6
|
|
7
|
-
|
7
|
+
# index [[ :word_id, Mongo::DESCENDING ]], :unique=>true
|
8
8
|
|
9
|
-
end
|
9
|
+
# end
|
@@ -8,32 +8,31 @@ module WhowishWord
|
|
8
8
|
include WhowishWord::Constant
|
9
9
|
include WhowishWord::Initializer
|
10
10
|
include WhowishWord::WordFor
|
11
|
-
include WhowishWord::Authentication
|
11
|
+
# include WhowishWord::Authentication
|
12
12
|
|
13
13
|
attr_accessor :words
|
14
14
|
|
15
|
-
def init(
|
16
|
-
|
17
|
-
@orm_engine = orm_engine
|
18
|
-
|
19
|
-
init_username_and_password
|
15
|
+
def init()
|
20
16
|
install_route
|
21
17
|
install_hook
|
22
18
|
load_rails
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
words = WhowishWordHtml.all()
|
27
|
-
|
28
|
-
@words = {}
|
29
|
-
words.each { |word|
|
30
|
-
@words[word.word_id] = word.content
|
31
|
-
}
|
32
|
-
|
33
|
-
end
|
20
|
+
Rails.configuration.i18n.load_path += Dir[Rails.root.join('config', 'locales', 'whowish_word', '**', '*.{rb,yml}')]
|
34
21
|
|
35
|
-
|
36
|
-
|
22
|
+
I18n.class_eval do
|
23
|
+
class << self
|
24
|
+
def translations
|
25
|
+
backend.send(:translations)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
I18n::MissingTranslation::Base.class_eval do
|
31
|
+
def html_message
|
32
|
+
key = keys.last.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
|
33
|
+
key
|
34
|
+
end
|
35
|
+
end
|
37
36
|
end
|
38
37
|
|
39
38
|
extend self
|