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,116 +1,116 @@
|
|
1
|
-
/**
|
2
|
-
* @author Tanin
|
3
|
-
*/
|
4
|
-
var whowishWordHelper = {};
|
5
|
-
|
6
|
-
whowishWordHelper.sanitize = function(content) {
|
7
|
-
return content.replace(whowishWordVariables.attributeValuePattern,"$2")
|
8
|
-
}
|
9
|
-
|
10
|
-
whowishWordHelper.match = function(content) {
|
11
|
-
return whowishWordHelper.matchWithResult(content) != null;
|
12
|
-
}
|
13
|
-
|
14
|
-
whowishWordHelper.matchWithResult = function(content) {
|
15
|
-
return content.match(whowishWordVariables.attributeValuePattern);
|
16
|
-
}
|
17
|
-
|
18
|
-
whowishWordHelper.makeEditIconId = function(element, name) {
|
19
|
-
return element.id +
|
20
|
-
whowishWordVariables.separator +
|
21
|
-
name;
|
22
|
-
}
|
23
|
-
|
24
|
-
whowishWordHelper.log = function(msg) {
|
25
|
-
try {
|
26
|
-
console.log(msg);
|
27
|
-
} catch (e) {}
|
28
|
-
};
|
29
|
-
|
30
|
-
whowishWordHelper.repositionAllEditIconPanels = function() {
|
31
|
-
|
32
|
-
var editIconPanels = $w('.whowishWordEditIconPanel');
|
33
|
-
for (var i=0;i<editIconPanels.length;i++) {
|
34
|
-
whowishWordStorage[editIconPanels[i].id].reposition();
|
35
|
-
}
|
36
|
-
|
37
|
-
};
|
38
|
-
|
39
|
-
|
40
|
-
whowishWordHelper.editIconPanelRepositioning = function() {
|
41
|
-
|
42
|
-
var elem = $w('#' + this.elementId)[0];
|
43
|
-
|
44
|
-
var pos = $w(elem).position();
|
45
|
-
var marginLeft = $w(elem).margin().left;
|
46
|
-
var marginTop = $w(elem).margin().top;
|
47
|
-
var outdent = 10;
|
48
|
-
|
49
|
-
$w('#' + this.editIconPanelId).css('position', 'absolute')
|
50
|
-
.css('left', (pos.left - outdent + marginLeft) + 'px')
|
51
|
-
.css('top', (pos.top - outdent + marginTop) + 'px');
|
52
|
-
|
53
|
-
};
|
54
|
-
|
55
|
-
|
56
|
-
whowishWordHelper.editHandler = function(event) {
|
57
|
-
|
58
|
-
event.stopPropagation();
|
59
|
-
event.preventDefault();
|
60
|
-
|
61
|
-
var self = this;
|
62
|
-
var customData = whowishWordStorage[this.id]
|
63
|
-
|
64
|
-
$w.whowishWordDialog.open({
|
65
|
-
|
66
|
-
whowishWordId: customData.id,
|
67
|
-
variables: customData.variables,
|
68
|
-
attributeName: customData.attributeName,
|
69
|
-
content: customData.contentHandler.getContent(),
|
70
|
-
success: function(html){
|
71
|
-
|
72
|
-
$w.whowishWordDialog.start_loading();
|
73
|
-
|
74
|
-
$w.ajax({
|
75
|
-
type: "POST",
|
76
|
-
url: '/whowish_word/change_word',
|
77
|
-
cache: false,
|
78
|
-
headers: {
|
79
|
-
"Connection": "close"
|
80
|
-
},
|
81
|
-
data: {
|
82
|
-
"word_id": customData.id,
|
83
|
-
"content": html
|
84
|
-
},
|
85
|
-
success: function(data) {
|
86
|
-
customData.contentHandler.setContent(html);
|
87
|
-
$w.whowishWordDialog.close();
|
88
|
-
$w.whowishWordDialog.stop_loading();
|
89
|
-
},
|
90
|
-
error: function(req, status, e){
|
91
|
-
alert('WhowishWord cannot save the data. The Ajax resquest is not sent. Please try again later.');
|
92
|
-
$w.whowishWordDialog.stop_loading();
|
93
|
-
}
|
94
|
-
});
|
95
|
-
|
96
|
-
}
|
97
|
-
});
|
98
|
-
|
99
|
-
};
|
100
|
-
|
101
|
-
|
102
|
-
whowishWordHelper.extractWhowishWordIdFromText = function(text) {
|
103
|
-
var result = whowishWordHelper.matchWithResult(text);
|
104
|
-
return result[1];
|
105
|
-
|
106
|
-
};
|
107
|
-
|
108
|
-
|
109
|
-
whowishWordHelper.parseWhowishWordIdPackage = function(whowishWordIdPackage){
|
110
|
-
var result = whowishWordIdPackage.match(whowishWordVariables.whowishWordIdPattern);
|
111
|
-
|
112
|
-
return {
|
113
|
-
id: result[1],
|
114
|
-
variables: result[3]
|
115
|
-
};
|
116
|
-
};
|
1
|
+
/**
|
2
|
+
* @author Tanin
|
3
|
+
*/
|
4
|
+
var whowishWordHelper = {};
|
5
|
+
|
6
|
+
whowishWordHelper.sanitize = function(content) {
|
7
|
+
return content.replace(whowishWordVariables.attributeValuePattern,"$2")
|
8
|
+
}
|
9
|
+
|
10
|
+
whowishWordHelper.match = function(content) {
|
11
|
+
return whowishWordHelper.matchWithResult(content) != null;
|
12
|
+
}
|
13
|
+
|
14
|
+
whowishWordHelper.matchWithResult = function(content) {
|
15
|
+
return content.match(whowishWordVariables.attributeValuePattern);
|
16
|
+
}
|
17
|
+
|
18
|
+
whowishWordHelper.makeEditIconId = function(element, name) {
|
19
|
+
return element.id +
|
20
|
+
whowishWordVariables.separator +
|
21
|
+
name;
|
22
|
+
}
|
23
|
+
|
24
|
+
whowishWordHelper.log = function(msg) {
|
25
|
+
try {
|
26
|
+
console.log(msg);
|
27
|
+
} catch (e) {}
|
28
|
+
};
|
29
|
+
|
30
|
+
whowishWordHelper.repositionAllEditIconPanels = function() {
|
31
|
+
|
32
|
+
var editIconPanels = $w('.whowishWordEditIconPanel');
|
33
|
+
for (var i=0;i<editIconPanels.length;i++) {
|
34
|
+
whowishWordStorage[editIconPanels[i].id].reposition();
|
35
|
+
}
|
36
|
+
|
37
|
+
};
|
38
|
+
|
39
|
+
|
40
|
+
whowishWordHelper.editIconPanelRepositioning = function() {
|
41
|
+
|
42
|
+
var elem = $w('#' + this.elementId)[0];
|
43
|
+
|
44
|
+
var pos = $w(elem).position();
|
45
|
+
var marginLeft = $w(elem).margin().left;
|
46
|
+
var marginTop = $w(elem).margin().top;
|
47
|
+
var outdent = 10;
|
48
|
+
|
49
|
+
$w('#' + this.editIconPanelId).css('position', 'absolute')
|
50
|
+
.css('left', (pos.left - outdent + marginLeft) + 'px')
|
51
|
+
.css('top', (pos.top - outdent + marginTop) + 'px');
|
52
|
+
|
53
|
+
};
|
54
|
+
|
55
|
+
|
56
|
+
whowishWordHelper.editHandler = function(event) {
|
57
|
+
|
58
|
+
event.stopPropagation();
|
59
|
+
event.preventDefault();
|
60
|
+
|
61
|
+
var self = this;
|
62
|
+
var customData = whowishWordStorage[this.id]
|
63
|
+
|
64
|
+
$w.whowishWordDialog.open({
|
65
|
+
|
66
|
+
whowishWordId: customData.id,
|
67
|
+
variables: customData.variables,
|
68
|
+
attributeName: customData.attributeName,
|
69
|
+
content: customData.contentHandler.getContent(),
|
70
|
+
success: function(html){
|
71
|
+
|
72
|
+
$w.whowishWordDialog.start_loading();
|
73
|
+
|
74
|
+
$w.ajax({
|
75
|
+
type: "POST",
|
76
|
+
url: '/whowish_word/change_word',
|
77
|
+
cache: false,
|
78
|
+
headers: {
|
79
|
+
"Connection": "close"
|
80
|
+
},
|
81
|
+
data: {
|
82
|
+
"word_id": customData.id,
|
83
|
+
"content": html
|
84
|
+
},
|
85
|
+
success: function(data) {
|
86
|
+
customData.contentHandler.setContent(html);
|
87
|
+
$w.whowishWordDialog.close();
|
88
|
+
$w.whowishWordDialog.stop_loading();
|
89
|
+
},
|
90
|
+
error: function(req, status, e){
|
91
|
+
alert('WhowishWord cannot save the data. The Ajax resquest is not sent. Please try again later.');
|
92
|
+
$w.whowishWordDialog.stop_loading();
|
93
|
+
}
|
94
|
+
});
|
95
|
+
|
96
|
+
}
|
97
|
+
});
|
98
|
+
|
99
|
+
};
|
100
|
+
|
101
|
+
|
102
|
+
whowishWordHelper.extractWhowishWordIdFromText = function(text) {
|
103
|
+
var result = whowishWordHelper.matchWithResult(text);
|
104
|
+
return result[1];
|
105
|
+
|
106
|
+
};
|
107
|
+
|
108
|
+
|
109
|
+
whowishWordHelper.parseWhowishWordIdPackage = function(whowishWordIdPackage){
|
110
|
+
var result = whowishWordIdPackage.match(whowishWordVariables.whowishWordIdPattern);
|
111
|
+
|
112
|
+
return {
|
113
|
+
id: result[1],
|
114
|
+
variables: result[3]
|
115
|
+
};
|
116
|
+
};
|
@@ -1,69 +1,69 @@
|
|
1
|
-
|
2
|
-
var WhowishWordCreator = Class.extend({
|
3
|
-
|
4
|
-
init: function(elem){
|
5
|
-
|
6
|
-
this.element = elem;
|
7
|
-
|
8
|
-
if (this.element.id == "" || this.element.id == undefined) {
|
9
|
-
this.element.id = "whowishWordId" + (whowishWordVariables.idRunner++);
|
10
|
-
}
|
11
|
-
|
12
|
-
if (this.element.tagName.toLowerCase() == "option") {
|
13
|
-
this.editIconPanel = (new WhowishWordSelectCreator($w(this.element).parent()[0])).editIconPanel;
|
14
|
-
} else {
|
15
|
-
this.editIconPanel = this.createAndGetEditIconPanel();
|
16
|
-
}
|
17
|
-
|
18
|
-
|
19
|
-
this.makeEditIcon();
|
20
|
-
this.sanitize();
|
21
|
-
|
22
|
-
},
|
23
|
-
|
24
|
-
makeEditIcon: function() {
|
25
|
-
throw 'makeEditIcon() is not implemented'
|
26
|
-
},
|
27
|
-
|
28
|
-
sanitize: function() {
|
29
|
-
throw 'sanitize() is not implemented'
|
30
|
-
},
|
31
|
-
|
32
|
-
addEditIcon: function(editIcon){
|
33
|
-
this.editIconPanel.appendChild(editIcon);
|
34
|
-
},
|
35
|
-
|
36
|
-
createAndGetEditIconPanel: function() {
|
37
|
-
|
38
|
-
if ($('#' + this.makeEditIconPanelId()).length > 0)
|
39
|
-
return $('#' + this.makeEditIconPanelId())[0];
|
40
|
-
|
41
|
-
var editIconPanel = document.createElement('span');
|
42
|
-
|
43
|
-
$w(editIconPanel).attr('id', this.makeEditIconPanelId())
|
44
|
-
.addClass('whowishWordEditIconPanel');
|
45
|
-
|
46
|
-
customData = {};
|
47
|
-
customData.editIconPanelId = editIconPanel.id;
|
48
|
-
customData.elementId = this.element.id;
|
49
|
-
customData.reposition = whowishWordHelper.editIconPanelRepositioning;
|
50
|
-
|
51
|
-
whowishWordStorage[editIconPanel.id] = customData;
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
whowishWordStorage[editIconPanel.id].reposition();
|
56
|
-
|
57
|
-
|
58
|
-
$w(this.element).after(editIconPanel);
|
59
|
-
|
60
|
-
return editIconPanel;
|
61
|
-
},
|
62
|
-
|
63
|
-
|
64
|
-
makeEditIconPanelId: function() {
|
65
|
-
return this.element.id + "EditPanel";
|
66
|
-
}
|
67
|
-
|
68
|
-
|
69
|
-
});
|
1
|
+
|
2
|
+
var WhowishWordCreator = Class.extend({
|
3
|
+
|
4
|
+
init: function(elem){
|
5
|
+
|
6
|
+
this.element = elem;
|
7
|
+
|
8
|
+
if (this.element.id == "" || this.element.id == undefined) {
|
9
|
+
this.element.id = "whowishWordId" + (whowishWordVariables.idRunner++);
|
10
|
+
}
|
11
|
+
|
12
|
+
if (this.element.tagName.toLowerCase() == "option") {
|
13
|
+
this.editIconPanel = (new WhowishWordSelectCreator($w(this.element).parent()[0])).editIconPanel;
|
14
|
+
} else {
|
15
|
+
this.editIconPanel = this.createAndGetEditIconPanel();
|
16
|
+
}
|
17
|
+
|
18
|
+
|
19
|
+
this.makeEditIcon();
|
20
|
+
this.sanitize();
|
21
|
+
|
22
|
+
},
|
23
|
+
|
24
|
+
makeEditIcon: function() {
|
25
|
+
throw 'makeEditIcon() is not implemented'
|
26
|
+
},
|
27
|
+
|
28
|
+
sanitize: function() {
|
29
|
+
throw 'sanitize() is not implemented'
|
30
|
+
},
|
31
|
+
|
32
|
+
addEditIcon: function(editIcon){
|
33
|
+
this.editIconPanel.appendChild(editIcon);
|
34
|
+
},
|
35
|
+
|
36
|
+
createAndGetEditIconPanel: function() {
|
37
|
+
|
38
|
+
if ($('#' + this.makeEditIconPanelId()).length > 0)
|
39
|
+
return $('#' + this.makeEditIconPanelId())[0];
|
40
|
+
|
41
|
+
var editIconPanel = document.createElement('span');
|
42
|
+
|
43
|
+
$w(editIconPanel).attr('id', this.makeEditIconPanelId())
|
44
|
+
.addClass('whowishWordEditIconPanel');
|
45
|
+
|
46
|
+
customData = {};
|
47
|
+
customData.editIconPanelId = editIconPanel.id;
|
48
|
+
customData.elementId = this.element.id;
|
49
|
+
customData.reposition = whowishWordHelper.editIconPanelRepositioning;
|
50
|
+
|
51
|
+
whowishWordStorage[editIconPanel.id] = customData;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
whowishWordStorage[editIconPanel.id].reposition();
|
56
|
+
|
57
|
+
|
58
|
+
$w(this.element).after(editIconPanel);
|
59
|
+
|
60
|
+
return editIconPanel;
|
61
|
+
},
|
62
|
+
|
63
|
+
|
64
|
+
makeEditIconPanelId: function() {
|
65
|
+
return this.element.id + "EditPanel";
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
});
|
@@ -1,41 +1,41 @@
|
|
1
|
-
require File.expand_path("../config", __FILE__)
|
2
|
-
require File.expand_path("../constant", __FILE__)
|
3
|
-
require File.expand_path("../initializer", __FILE__)
|
4
|
-
require File.expand_path("../word_for", __FILE__)
|
5
|
-
require File.expand_path("../authentication", __FILE__)
|
6
|
-
|
7
|
-
module WhowishWord
|
8
|
-
include WhowishWord::Constant
|
9
|
-
include WhowishWord::Initializer
|
10
|
-
include WhowishWord::WordFor
|
11
|
-
include WhowishWord::Authentication
|
12
|
-
|
13
|
-
attr_accessor :words
|
14
|
-
|
15
|
-
def init(orm_engine = :active_record)
|
16
|
-
|
17
|
-
@orm_engine = orm_engine
|
18
|
-
|
19
|
-
init_username_and_password
|
20
|
-
install_route
|
21
|
-
install_hook
|
22
|
-
load_rails
|
23
|
-
|
24
|
-
run_database_migration
|
25
|
-
|
26
|
-
words = WhowishWordHtml.all()
|
27
|
-
|
28
|
-
@words = {}
|
29
|
-
words.each { |word|
|
30
|
-
@words[word.word_id] = word.content
|
31
|
-
}
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def add_or_set_word(word_id, content)
|
36
|
-
@words[word_id] = content
|
37
|
-
end
|
38
|
-
|
39
|
-
extend self
|
40
|
-
end
|
41
|
-
|
1
|
+
require File.expand_path("../config", __FILE__)
|
2
|
+
require File.expand_path("../constant", __FILE__)
|
3
|
+
require File.expand_path("../initializer", __FILE__)
|
4
|
+
require File.expand_path("../word_for", __FILE__)
|
5
|
+
require File.expand_path("../authentication", __FILE__)
|
6
|
+
|
7
|
+
module WhowishWord
|
8
|
+
include WhowishWord::Constant
|
9
|
+
include WhowishWord::Initializer
|
10
|
+
include WhowishWord::WordFor
|
11
|
+
include WhowishWord::Authentication
|
12
|
+
|
13
|
+
attr_accessor :words
|
14
|
+
|
15
|
+
def init(orm_engine = :active_record)
|
16
|
+
|
17
|
+
@orm_engine = orm_engine
|
18
|
+
|
19
|
+
init_username_and_password
|
20
|
+
install_route
|
21
|
+
install_hook
|
22
|
+
load_rails
|
23
|
+
|
24
|
+
run_database_migration
|
25
|
+
|
26
|
+
words = WhowishWordHtml.all()
|
27
|
+
|
28
|
+
@words = {}
|
29
|
+
words.each { |word|
|
30
|
+
@words[word.word_id] = word.content
|
31
|
+
}
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_or_set_word(word_id, content)
|
36
|
+
@words[word_id] = content
|
37
|
+
end
|
38
|
+
|
39
|
+
extend self
|
40
|
+
end
|
41
|
+
|
@@ -1,94 +1,94 @@
|
|
1
|
-
require File.expand_path("../constant", __FILE__)
|
2
|
-
|
3
|
-
module WhowishWord
|
4
|
-
|
5
|
-
module WordFor
|
6
|
-
include WhowishWord::Constant
|
7
|
-
|
8
|
-
def word_for(namespace, id, locale, *variables)
|
9
|
-
return word_for_normal_mode(namespace, id, locale, *variables)
|
10
|
-
end
|
11
|
-
|
12
|
-
def word_for_attr(namespace, id, locale, *variables)
|
13
|
-
return word_for_normal_mode(namespace, id, locale, *variables)
|
14
|
-
end
|
15
|
-
|
16
|
-
def word_for_in_edit_mode(namespace, id, locale, *variables)
|
17
|
-
return "<dfn>#{word_for_edit_mode(namespace, id, locale, *variables)}</dfn>".html_safe
|
18
|
-
end
|
19
|
-
|
20
|
-
def word_for_attr_in_edit_mode(namespace, id, locale, *variables)
|
21
|
-
return word_for_edit_mode(namespace, id, locale, *variables)
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def word_for_edit_mode(namespace, id, locale, *variables)
|
26
|
-
|
27
|
-
variables = sanitize_variables_arg(variables)
|
28
|
-
|
29
|
-
variable_suffix = ""
|
30
|
-
if variables.length > 0
|
31
|
-
|
32
|
-
var_keys = []
|
33
|
-
variables.map { |key,val| var_keys.push("#{key}") }
|
34
|
-
|
35
|
-
variable_suffix = "|#{var_keys.join(",")}"
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
return PREFIX + \
|
40
|
-
SEPARATOR + \
|
41
|
-
get_whowish_word_id(namespace, id, locale) + \
|
42
|
-
variable_suffix + \
|
43
|
-
SEPARATOR + \
|
44
|
-
word_for_normal_mode(namespace, id, locale, variables)
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
def sanitize_variables_arg(variables)
|
49
|
-
|
50
|
-
if variables.length > 0
|
51
|
-
variables = variables[0]
|
52
|
-
else
|
53
|
-
variables = {}
|
54
|
-
end
|
55
|
-
|
56
|
-
return variables
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
def word_for_normal_mode(namespace, id, locale, *variables)
|
61
|
-
|
62
|
-
variables = sanitize_variables_arg(variables)
|
63
|
-
|
64
|
-
word_id = get_whowish_word_id(namespace, id, locale)
|
65
|
-
|
66
|
-
if @words[word_id]
|
67
|
-
|
68
|
-
content = "#{@words[word_id]}"
|
69
|
-
variables.each_pair { |key,val| content.gsub!("{#{key}}","#{val}") }
|
70
|
-
|
71
|
-
else
|
72
|
-
|
73
|
-
content = "#{id}(#{locale})"
|
74
|
-
|
75
|
-
if variables.length > 0
|
76
|
-
content_params = []
|
77
|
-
variables.each_pair { |key,val| content_params.push("#{key}") }
|
78
|
-
content += "{#{content_params.join(',')}}"
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
return content.html_safe
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
def get_whowish_word_id(namespace, id, locale)
|
89
|
-
"#{namespace}:#{id}(#{locale})".downcase
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
1
|
+
require File.expand_path("../constant", __FILE__)
|
2
|
+
|
3
|
+
module WhowishWord
|
4
|
+
|
5
|
+
module WordFor
|
6
|
+
include WhowishWord::Constant
|
7
|
+
|
8
|
+
def word_for(namespace, id, locale, *variables)
|
9
|
+
return word_for_normal_mode(namespace, id, locale, *variables)
|
10
|
+
end
|
11
|
+
|
12
|
+
def word_for_attr(namespace, id, locale, *variables)
|
13
|
+
return word_for_normal_mode(namespace, id, locale, *variables)
|
14
|
+
end
|
15
|
+
|
16
|
+
def word_for_in_edit_mode(namespace, id, locale, *variables)
|
17
|
+
return "<dfn>#{word_for_edit_mode(namespace, id, locale, *variables)}</dfn>".html_safe
|
18
|
+
end
|
19
|
+
|
20
|
+
def word_for_attr_in_edit_mode(namespace, id, locale, *variables)
|
21
|
+
return word_for_edit_mode(namespace, id, locale, *variables)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def word_for_edit_mode(namespace, id, locale, *variables)
|
26
|
+
|
27
|
+
variables = sanitize_variables_arg(variables)
|
28
|
+
|
29
|
+
variable_suffix = ""
|
30
|
+
if variables.length > 0
|
31
|
+
|
32
|
+
var_keys = []
|
33
|
+
variables.map { |key,val| var_keys.push("#{key}") }
|
34
|
+
|
35
|
+
variable_suffix = "|#{var_keys.join(",")}"
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
return PREFIX + \
|
40
|
+
SEPARATOR + \
|
41
|
+
get_whowish_word_id(namespace, id, locale) + \
|
42
|
+
variable_suffix + \
|
43
|
+
SEPARATOR + \
|
44
|
+
word_for_normal_mode(namespace, id, locale, variables)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def sanitize_variables_arg(variables)
|
49
|
+
|
50
|
+
if variables.length > 0
|
51
|
+
variables = variables[0]
|
52
|
+
else
|
53
|
+
variables = {}
|
54
|
+
end
|
55
|
+
|
56
|
+
return variables
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def word_for_normal_mode(namespace, id, locale, *variables)
|
61
|
+
|
62
|
+
variables = sanitize_variables_arg(variables)
|
63
|
+
|
64
|
+
word_id = get_whowish_word_id(namespace, id, locale)
|
65
|
+
|
66
|
+
if @words[word_id]
|
67
|
+
|
68
|
+
content = "#{@words[word_id]}"
|
69
|
+
variables.each_pair { |key,val| content.gsub!("{#{key}}","#{val}") }
|
70
|
+
|
71
|
+
else
|
72
|
+
|
73
|
+
content = "#{id}(#{locale})"
|
74
|
+
|
75
|
+
if variables.length > 0
|
76
|
+
content_params = []
|
77
|
+
variables.each_pair { |key,val| content_params.push("#{key}") }
|
78
|
+
content += "{#{content_params.join(',')}}"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
return content.html_safe
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def get_whowish_word_id(namespace, id, locale)
|
89
|
+
"#{namespace}:#{id}(#{locale})".downcase
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
94
|
end
|
data/rails/Gemfile
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
source 'http://rubygems.org'
|
2
|
-
|
3
|
-
gem 'rails'
|
4
|
-
gem 'rake','0.8.7'
|
5
|
-
|
6
|
-
gem 'rspec-rails'
|
7
|
-
gem 'watir-webdriver-rails'
|
8
|
-
|
9
|
-
group :active_record do
|
10
|
-
gem 'sqlite3'
|
11
|
-
end
|
12
|
-
|
13
|
-
group :mongoid do
|
14
|
-
gem 'mongoid'
|
15
|
-
gem 'bson_ext'
|
16
|
-
end
|
17
|
-
|
18
|
-
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails'
|
4
|
+
gem 'rake','0.8.7'
|
5
|
+
|
6
|
+
gem 'rspec-rails'
|
7
|
+
gem 'watir-webdriver-rails'
|
8
|
+
|
9
|
+
group :active_record do
|
10
|
+
gem 'sqlite3'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :mongoid do
|
14
|
+
gem 'mongoid'
|
15
|
+
gem 'bson_ext'
|
16
|
+
end
|
17
|
+
|
18
|
+
|