whowish_word 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -5
- data/.loadpath +5 -5
- data/.project +18 -17
- data/Gemfile +2 -2
- data/HOW_TO_BUILD_WHOWISH_HOOK.md +9 -9
- data/ISSUE.md +93 -93
- data/README.md +208 -208
- data/lib/whowish_word/action_controller/base.rb +44 -44
- data/lib/whowish_word/action_mailer/base.rb +11 -11
- data/lib/whowish_word/action_view/base.rb +70 -70
- data/lib/whowish_word/action_view/template.rb +30 -30
- data/lib/whowish_word/authentication.rb +13 -13
- data/lib/whowish_word/config.rb +21 -21
- data/lib/whowish_word/constant.rb +8 -8
- data/lib/whowish_word/db_migration/active_record/whowish_word_html.rb +14 -14
- data/lib/whowish_word/db_migration/mongoid/whowish_word_html.rb +5 -5
- data/lib/whowish_word/initializer.rb +52 -52
- data/lib/whowish_word/rails/app/controllers/whowish_word_controller.rb +60 -60
- data/lib/whowish_word/rails/app/models/active_record/whowish_word_html.rb +3 -3
- data/lib/whowish_word/rails/app/models/mongoid/whowish_word_html.rb +8 -8
- data/lib/whowish_word/rails/public/javascripts/0_jquery-1.6.4-whowish_word.js +9046 -9046
- data/lib/whowish_word/rails/public/javascripts/1_csrf_token_hook.js +9 -9
- data/lib/whowish_word/rails/public/javascripts/1_jquery.loading_button.js +66 -66
- data/lib/whowish_word/rails/public/javascripts/2_whowish_word_variables.js +33 -33
- data/lib/whowish_word/rails/public/javascripts/3_whowish_word_dialog.js +136 -136
- data/lib/whowish_word/rails/public/javascripts/3_whowish_word_helper.js +116 -116
- data/lib/whowish_word/rails/public/javascripts/4_whowish_word_creator.js +69 -69
- data/lib/whowish_word/whowish_word.rb +41 -41
- data/lib/whowish_word/word_for.rb +93 -93
- data/rails/Gemfile +18 -18
- data/rails/Gemfile.lock +63 -64
- data/rails/app/controllers/application_controller.rb +22 -22
- data/rails/app/controllers/home_controller.rb +8 -8
- data/rails/app/views/home/index.html.erb +109 -109
- data/rails/app/views/home/static_edit.html.erb +50 -50
- data/rails/app/views/home/static_edit_select.html.erb +8 -8
- 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 +3 -3
- data/rails/app/views/integration/value.html.erb +1 -1
- data/rails/app/views/layouts/integration.html.erb +14 -14
- data/rails/app/views/layouts/main.html.erb +13 -13
- data/rails/app/views/layouts/nested_test_word_for.html.erb +17 -17
- data/rails/app/views/layouts/test_javascript.html.erb +13 -13
- data/rails/app/views/layouts/test_word_for.html.erb +24 -24
- data/rails/app/views/test_javascript/change_value.html.erb +32 -32
- data/rails/app/views/test_javascript/index.html.erb +87 -87
- data/rails/app/views/test_javascript/replace_with_html.html.erb +96 -96
- data/rails/app/views/test_word_for/_partial.html.erb +4 -4
- data/rails/app/views/test_word_for/index.html.erb +8 -8
- data/rails/config/application.rb +30 -30
- data/rails/config/boot.rb +9 -9
- data/rails/config/database.yml +24 -24
- data/rails/config/environment.rb +16 -16
- data/rails/config/initializers/whowish_word.rb +3 -3
- data/rails/config/mongoid.rb +6 -6
- data/rails/config/mongoid.yml +14 -14
- data/rails/config/routes.rb +7 -7
- data/rails/config.ru +4 -4
- data/rails/log/.gitignore +1 -1
- data/rails/mongo.bat +4 -4
- data/rails/public/javascripts/jquery.loading_button.js +72 -72
- data/rails/public/test/jquery_version.html +26 -26
- data/rails/script/rails +6 -6
- data/rails/spec/controllers/whowish_word_controller_spec.rb +55 -55
- data/rails/spec/integration/whowish_word_generator_spec.rb +139 -139
- data/rails/spec/integration/whowish_word_spec.rb +116 -116
- data/rails/spec/spec_helper.rb +34 -36
- data/rails/spec/support/browser.rb +193 -193
- data/rails/spec/support/json_rspec_helper.rb +8 -8
- data/rails/spec/support/mongoid_helper.rb +9 -9
- data/spec/spec_helper.rb +17 -19
- data/spec/unit/word_for_attr_in_edit_mode_spec.rb +43 -43
- data/spec/unit/word_for_attr_spec.rb +43 -43
- data/spec/unit/word_for_in_edit_mode_spec.rb +43 -43
- data/spec/unit/word_for_spec.rb +43 -43
- data/whowish_word.gemspec +21 -21
- metadata +73 -4
@@ -1,31 +1,31 @@
|
|
1
|
-
|
2
|
-
if defined?(ActionView) and defined?(ActionView::Base)
|
3
|
-
|
4
|
-
class ActionView::Template
|
5
|
-
|
6
|
-
alias_method :render_original, :render
|
7
|
-
|
8
|
-
def render(view, locals, buffer=nil, &block)
|
9
|
-
|
10
|
-
previous_whowish_word_page = nil
|
11
|
-
|
12
|
-
if view.instance_variable_defined?(:@whowish_word_page)
|
13
|
-
previous_whowish_word_page = view.instance_variable_get(:@whowish_word_page)
|
14
|
-
end
|
15
|
-
|
16
|
-
view.instance_variable_set(:@whowish_word_page, @identifier)
|
17
|
-
|
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
|
-
|
22
|
-
html = render_original(view, locals, buffer, &block)
|
23
|
-
|
24
|
-
view.instance_variable_set(:@whowish_word_page, previous_whowish_word_page)
|
25
|
-
|
26
|
-
return html
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
1
|
+
|
2
|
+
if defined?(ActionView) and defined?(ActionView::Base)
|
3
|
+
|
4
|
+
class ActionView::Template
|
5
|
+
|
6
|
+
alias_method :render_original, :render
|
7
|
+
|
8
|
+
def render(view, locals, buffer=nil, &block)
|
9
|
+
|
10
|
+
previous_whowish_word_page = nil
|
11
|
+
|
12
|
+
if view.instance_variable_defined?(:@whowish_word_page)
|
13
|
+
previous_whowish_word_page = view.instance_variable_get(:@whowish_word_page)
|
14
|
+
end
|
15
|
+
|
16
|
+
view.instance_variable_set(:@whowish_word_page, @identifier)
|
17
|
+
|
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
|
+
|
22
|
+
html = render_original(view, locals, buffer, &block)
|
23
|
+
|
24
|
+
view.instance_variable_set(:@whowish_word_page, previous_whowish_word_page)
|
25
|
+
|
26
|
+
return html
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
31
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module WhowishWord
|
2
|
-
|
3
|
-
module Authentication
|
4
|
-
|
5
|
-
attr_accessor :username, :password
|
6
|
-
|
7
|
-
def init_username_and_password
|
8
|
-
@username ||= "whowishword"
|
9
|
-
@password ||= "pass"
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
1
|
+
module WhowishWord
|
2
|
+
|
3
|
+
module Authentication
|
4
|
+
|
5
|
+
attr_accessor :username, :password
|
6
|
+
|
7
|
+
def init_username_and_password
|
8
|
+
@username ||= "whowishword"
|
9
|
+
@password ||= "pass"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
14
|
end
|
data/lib/whowish_word/config.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
module WhowishWord
|
2
|
-
|
3
|
-
class Config
|
4
|
-
|
5
|
-
attr_accessor :locale, :edit_mode
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@locale = "en"
|
9
|
-
@edit_mode = false
|
10
|
-
end
|
11
|
-
|
12
|
-
def activate_edit_mode
|
13
|
-
@edit_mode = true
|
14
|
-
end
|
15
|
-
|
16
|
-
def set_locale(locale)
|
17
|
-
@locale = locale
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
1
|
+
module WhowishWord
|
2
|
+
|
3
|
+
class Config
|
4
|
+
|
5
|
+
attr_accessor :locale, :edit_mode
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@locale = "en"
|
9
|
+
@edit_mode = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def activate_edit_mode
|
13
|
+
@edit_mode = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_locale(locale)
|
17
|
+
@locale = locale
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
22
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module WhowishWord
|
2
|
-
|
3
|
-
module Constant
|
4
|
-
PREFIX = "__whowishWord__"
|
5
|
-
SEPARATOR = "_____"
|
6
|
-
ID_VARIABLES_SEPARATOR = "|"
|
7
|
-
end
|
8
|
-
|
1
|
+
module WhowishWord
|
2
|
+
|
3
|
+
module Constant
|
4
|
+
PREFIX = "__whowishWord__"
|
5
|
+
SEPARATOR = "_____"
|
6
|
+
ID_VARIABLES_SEPARATOR = "|"
|
7
|
+
end
|
8
|
+
|
9
9
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
begin
|
2
|
-
ActiveRecord::Schema.define do
|
3
|
-
|
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
|
-
|
9
|
-
add_index :whowish_word_htmls, :word_id, :unique => true
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
rescue Exception=>e
|
14
|
-
|
1
|
+
begin
|
2
|
+
ActiveRecord::Schema.define do
|
3
|
+
|
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
|
+
|
9
|
+
add_index :whowish_word_htmls, :word_id, :unique => true
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
rescue Exception=>e
|
14
|
+
|
15
15
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
begin
|
2
|
-
WhowishWordHtml.collection.drop_indexes
|
3
|
-
WhowishWordHtml.create_indexes
|
4
|
-
rescue Exception=>e
|
5
|
-
|
1
|
+
begin
|
2
|
+
WhowishWordHtml.collection.drop_indexes
|
3
|
+
WhowishWordHtml.create_indexes
|
4
|
+
rescue Exception=>e
|
5
|
+
|
6
6
|
end
|
@@ -1,53 +1,53 @@
|
|
1
|
-
module WhowishWord
|
2
|
-
|
3
|
-
module Initializer
|
4
|
-
|
5
|
-
def install_route
|
6
|
-
|
7
|
-
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
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def run_database_migration
|
16
|
-
|
17
|
-
Dir[File.expand_path("../db_migration/#{@orm_engine}/**/*.rb", __FILE__)].each {|f| require f}
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def install_hook
|
24
|
-
|
25
|
-
Dir[File.expand_path("../action_controller/**/*.rb", __FILE__)].each {|f| require f}
|
26
|
-
Dir[File.expand_path("../action_mailer/**/*.rb", __FILE__)].each {|f| require f}
|
27
|
-
Dir[File.expand_path("../action_view/**/*.rb", __FILE__)].each {|f| require f}
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def load_rails
|
33
|
-
|
34
|
-
paths = ["controllers","models/#{@orm_engine}"]
|
35
|
-
|
36
|
-
# load all controllers, helpers, and models
|
37
|
-
paths.each do |dir|
|
38
|
-
|
39
|
-
path = File.join(File.dirname(__FILE__), 'rails', 'app', dir)
|
40
|
-
|
41
|
-
$LOAD_PATH.insert(0, path)
|
42
|
-
ActiveSupport::Dependencies.autoload_paths.insert(0, path)
|
43
|
-
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
ActionController::Base.append_view_path(File.join(File.dirname(__FILE__), 'rails', 'app'))
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
1
|
+
module WhowishWord
|
2
|
+
|
3
|
+
module Initializer
|
4
|
+
|
5
|
+
def install_route
|
6
|
+
|
7
|
+
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
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_database_migration
|
16
|
+
|
17
|
+
Dir[File.expand_path("../db_migration/#{@orm_engine}/**/*.rb", __FILE__)].each {|f| require f}
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
def install_hook
|
24
|
+
|
25
|
+
Dir[File.expand_path("../action_controller/**/*.rb", __FILE__)].each {|f| require f}
|
26
|
+
Dir[File.expand_path("../action_mailer/**/*.rb", __FILE__)].each {|f| require f}
|
27
|
+
Dir[File.expand_path("../action_view/**/*.rb", __FILE__)].each {|f| require f}
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def load_rails
|
33
|
+
|
34
|
+
paths = ["controllers","models/#{@orm_engine}"]
|
35
|
+
|
36
|
+
# load all controllers, helpers, and models
|
37
|
+
paths.each do |dir|
|
38
|
+
|
39
|
+
path = File.join(File.dirname(__FILE__), 'rails', 'app', dir)
|
40
|
+
|
41
|
+
$LOAD_PATH.insert(0, path)
|
42
|
+
ActiveSupport::Dependencies.autoload_paths.insert(0, path)
|
43
|
+
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
ActionController::Base.append_view_path(File.join(File.dirname(__FILE__), 'rails', 'app'))
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
53
|
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
class WhowishWordController < ActionController::Base
|
2
|
-
|
3
|
-
def css
|
4
|
-
|
5
|
-
text = ""
|
6
|
-
|
7
|
-
Dir[File.expand_path("../../../public/stylesheets/*.css", __FILE__)].each { |f|
|
8
|
-
text += IO.read(f)
|
9
|
-
text += "\n\n"
|
10
|
-
}
|
11
|
-
|
12
|
-
response.headers["Content-Type"] = "text/css; charset=utf-8"
|
13
|
-
render :text=>text
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def js
|
18
|
-
|
19
|
-
text = ""
|
20
|
-
|
21
|
-
all_files = Dir[File.expand_path("../../../public/javascripts/*.js", __FILE__)]
|
22
|
-
all_files.sort! { |a, b| a <=> b}
|
23
|
-
|
24
|
-
all_files.each { |file|
|
25
|
-
text += IO.read(file)
|
26
|
-
text += "\n\n"
|
27
|
-
}
|
28
|
-
|
29
|
-
response.headers["Content-Type"] = "text/javascript; charset=utf-8"
|
30
|
-
render :text=>text
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def change_word
|
35
|
-
|
36
|
-
entity = WhowishWordHtml.first(:conditions=>{:word_id => params[:word_id].strip})
|
37
|
-
|
38
|
-
entity = WhowishWordHtml.new if !entity
|
39
|
-
|
40
|
-
entity.word_id = params[:word_id].strip
|
41
|
-
entity.content = params[:content].strip
|
42
|
-
|
43
|
-
if !entity.save
|
44
|
-
|
45
|
-
error_message = "WhowishWord fails to change the word you specified.<br/>" + \
|
46
|
-
"Possible causes:<br/>" + \
|
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
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
WhowishWord.add_or_set_word(entity.word_id, entity.content)
|
56
|
-
|
57
|
-
render :json=>{:ok=>true}
|
58
|
-
end
|
59
|
-
|
60
|
-
|
1
|
+
class WhowishWordController < ActionController::Base
|
2
|
+
|
3
|
+
def css
|
4
|
+
|
5
|
+
text = ""
|
6
|
+
|
7
|
+
Dir[File.expand_path("../../../public/stylesheets/*.css", __FILE__)].each { |f|
|
8
|
+
text += IO.read(f)
|
9
|
+
text += "\n\n"
|
10
|
+
}
|
11
|
+
|
12
|
+
response.headers["Content-Type"] = "text/css; charset=utf-8"
|
13
|
+
render :text=>text
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def js
|
18
|
+
|
19
|
+
text = ""
|
20
|
+
|
21
|
+
all_files = Dir[File.expand_path("../../../public/javascripts/*.js", __FILE__)]
|
22
|
+
all_files.sort! { |a, b| a <=> b}
|
23
|
+
|
24
|
+
all_files.each { |file|
|
25
|
+
text += IO.read(file)
|
26
|
+
text += "\n\n"
|
27
|
+
}
|
28
|
+
|
29
|
+
response.headers["Content-Type"] = "text/javascript; charset=utf-8"
|
30
|
+
render :text=>text
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def change_word
|
35
|
+
|
36
|
+
entity = WhowishWordHtml.first(:conditions=>{:word_id => params[:word_id].strip})
|
37
|
+
|
38
|
+
entity = WhowishWordHtml.new if !entity
|
39
|
+
|
40
|
+
entity.word_id = params[:word_id].strip
|
41
|
+
entity.content = params[:content].strip
|
42
|
+
|
43
|
+
if !entity.save
|
44
|
+
|
45
|
+
error_message = "WhowishWord fails to change the word you specified.<br/>" + \
|
46
|
+
"Possible causes:<br/>" + \
|
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
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
WhowishWord.add_or_set_word(entity.word_id, entity.content)
|
56
|
+
|
57
|
+
render :json=>{:ok=>true}
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
61
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class WhowishWordHtml < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
1
|
+
class WhowishWordHtml < ActiveRecord::Base
|
2
|
+
|
3
|
+
|
4
4
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class WhowishWordHtml
|
2
|
-
include Mongoid::Document
|
3
|
-
|
4
|
-
field :word_id,:type=>String
|
5
|
-
field :content, :type=>String
|
6
|
-
|
7
|
-
index [[ :word_id, Mongo::DESCENDING ]], :unique=>true
|
8
|
-
|
1
|
+
class WhowishWordHtml
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :word_id,:type=>String
|
5
|
+
field :content, :type=>String
|
6
|
+
|
7
|
+
index [[ :word_id, Mongo::DESCENDING ]], :unique=>true
|
8
|
+
|
9
9
|
end
|