rmake-notation 0.0.2 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +19 -0
- data/lib/rmake-notation/version.rb +1 -1
- data/lib/rmake-notation.rb +387 -373
- data/lib/rmake-util.rb +1 -1
- metadata +3 -2
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Rmake Developers
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -30,6 +30,25 @@ Railsで使う際は、controllerに以下のように記述しています。he
|
|
30
30
|
|
31
31
|
helper_method :generate_contents
|
32
32
|
|
33
|
+
## PLUGIN
|
34
|
+
|
35
|
+
Rmake記法はプラグインで拡張することができます。[version]と記述すると、本gemのバージョンを返すプラグインは以下のように記述することができます。
|
36
|
+
|
37
|
+
class VersionPlugin
|
38
|
+
def target?(command)
|
39
|
+
command == "version"
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(command, block)
|
43
|
+
Rmake::Notation::VERSION.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# registration
|
48
|
+
@notation = Object.new.extend Rmake::Notation
|
49
|
+
@notation.add_plugin(VersionPlugin.new)
|
50
|
+
@notation.generate_contents(content)
|
51
|
+
|
33
52
|
## LICENSE
|
34
53
|
|
35
54
|
MIT License
|
data/lib/rmake-notation.rb
CHANGED
@@ -1,373 +1,387 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "rmake-util"
|
4
|
-
require "rmake-notation/version"
|
5
|
-
|
6
|
-
module Rmake::Notation
|
7
|
-
DOMAIN = "rmake.jp"
|
8
|
-
|
9
|
-
def generate_contents(content)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
blocks
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
message
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
block = self.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
result = "<
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
result = "<
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
url = "http://#{DOMAIN}/games/#{id}/play"
|
238
|
-
result =
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
url = "http://#{DOMAIN}/
|
252
|
-
result =
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
when "
|
318
|
-
id = parsed_block[1]
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rmake-util"
|
4
|
+
require "rmake-notation/version"
|
5
|
+
|
6
|
+
module Rmake::Notation
|
7
|
+
DOMAIN = "rmake.jp"
|
8
|
+
|
9
|
+
def generate_contents(content)
|
10
|
+
@title_list ||= []
|
11
|
+
|
12
|
+
result = ''
|
13
|
+
blocks = self.to_blocks(content)
|
14
|
+
|
15
|
+
blocks.each do |b|
|
16
|
+
block = self.block_to_html(b)
|
17
|
+
result += block
|
18
|
+
end
|
19
|
+
|
20
|
+
#result += " ********** " + blocks.join(",")
|
21
|
+
result.gsub("-)", "]")
|
22
|
+
|
23
|
+
rescue => err
|
24
|
+
message = err.message + "\n"
|
25
|
+
message += err.backtrace.join("\n")
|
26
|
+
message += "文章にエラーもしくは不正な文字が含まれているようです。確認してください。"
|
27
|
+
end
|
28
|
+
|
29
|
+
def title_list
|
30
|
+
@title_list
|
31
|
+
end
|
32
|
+
|
33
|
+
def reflesh_title_list
|
34
|
+
@title_list = []
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_plugin(plugin)
|
38
|
+
@plugins ||= []
|
39
|
+
|
40
|
+
if (plugin.respond_to?(:target?) && plugin.respond_to?(:execute))
|
41
|
+
@plugins << plugin
|
42
|
+
true
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_blocks(content)
|
49
|
+
contents = Array.new
|
50
|
+
# content.gsub(/(^[|].*?(\n)[^|])|(^[-].*?(?=((^[^-])|\z)))|(^[{][{][{].*?[}][}][}])|(^[\[].*?[\]])|(^[!]*.*?$)|(^http[:][\/][\/])|(?!^).*?$/m) {|s|
|
51
|
+
content.gsub(/(^[|][|][|].*?[|][|][|])|(^[|].*?(?=(^[^|]|\z)))|(^[-].*?(?=((^[^-])|\z)))|(^[{][{][{].*?[}][}][}])|([\[].*?[\]])|(^[!]*.*?$)|(^http[:][\/][\/])|(^https[:][\/][\/])|(?!^).*?$/m) {|s|
|
52
|
+
contents << s
|
53
|
+
}
|
54
|
+
contents
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_table_line(block)
|
58
|
+
header = true
|
59
|
+
style = ""
|
60
|
+
tag = "td style=\"#{style}\""
|
61
|
+
code_reg = /[{][{][{].*?[}][}][}]/m
|
62
|
+
|
63
|
+
pcodes = []
|
64
|
+
block_text = block
|
65
|
+
pcode_count = 0
|
66
|
+
while block_text.index(code_reg)
|
67
|
+
pcodes << self.generate_contents(block_text.slice(code_reg))
|
68
|
+
block_text = block_text.sub(code_reg, "___dummy_pcodes___")
|
69
|
+
|
70
|
+
pcode_count += 1
|
71
|
+
end
|
72
|
+
|
73
|
+
s_arr = block_text.split("\n")
|
74
|
+
s = ""
|
75
|
+
line_index = 0
|
76
|
+
temp_item = ""
|
77
|
+
|
78
|
+
s_arr.each do |item|
|
79
|
+
temp_item += item
|
80
|
+
|
81
|
+
if item.index("|||") == 0
|
82
|
+
temp_item = ""
|
83
|
+
if item.index("header:none")
|
84
|
+
header = false
|
85
|
+
end
|
86
|
+
|
87
|
+
elsif temp_item.rindex(/[|]/).to_i == temp_item.length - 2
|
88
|
+
item = temp_item
|
89
|
+
|
90
|
+
if line_index == 0 && header
|
91
|
+
tag = "th style=\"#{style}\""
|
92
|
+
end
|
93
|
+
|
94
|
+
item = "<tr><#{tag}>" + item[item.index('|') + 1..item.rindex('|') - 1] + "</#{tag}></tr>"
|
95
|
+
|
96
|
+
items_before = item.split('|')
|
97
|
+
items_after = []
|
98
|
+
items_before.each do |before|
|
99
|
+
items_after << self.generate_contents(before).gsub("<br />", "")
|
100
|
+
end
|
101
|
+
|
102
|
+
s += items_after.join("</#{tag}><#{tag}>")
|
103
|
+
|
104
|
+
line_index += 1
|
105
|
+
temp_item = ""
|
106
|
+
tag = "td style=\"#{style}\""
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
pcodes.each do |pcode|
|
112
|
+
s = s.sub("___dummy_pcodes___", pcode)
|
113
|
+
end
|
114
|
+
|
115
|
+
block = "<table class=\"table\">#{s}</table>"
|
116
|
+
end
|
117
|
+
|
118
|
+
def block_to_html(block)
|
119
|
+
case block
|
120
|
+
when /\A[\[]/
|
121
|
+
parsed_block = self.parse_inline(block)
|
122
|
+
block = self.inline_to_html(parsed_block)
|
123
|
+
when /(\A[{][{][{])/
|
124
|
+
parsed_block = self.parse_inline(block.gsub("{{{", "[").gsub("}}}", "]"))
|
125
|
+
block = self.inline_to_html(parsed_block)
|
126
|
+
when /^[!]/
|
127
|
+
len = block.length - block.gsub!(/^[!]*/, "").length + 2
|
128
|
+
s = generate_contents(block)
|
129
|
+
a_name = "#{@title_list.length + 1}_#{len}"
|
130
|
+
@title_list << [s, len, a_name]
|
131
|
+
block = "<h#{len}><a name=\"#{a_name}\"></a>#{s}</h#{len}>"
|
132
|
+
|
133
|
+
when /^[|][|][|]/
|
134
|
+
block = self.process_table_line(block)
|
135
|
+
|
136
|
+
when /^[|]/
|
137
|
+
s_arr = block.split("\n")
|
138
|
+
#s_arr.pop
|
139
|
+
s = ""
|
140
|
+
line_index = 0
|
141
|
+
s_arr.each do |item|
|
142
|
+
if line_index == 0
|
143
|
+
item = '<tr><th>' + item[item.index('|') + 1..item.rindex('|') - 1] + '</th></tr>'
|
144
|
+
s += item.split('|').join('</th><th>')
|
145
|
+
else
|
146
|
+
item = '<tr><td>' + item[item.index('|') + 1..item.rindex('|') - 1] + '</td></tr>'
|
147
|
+
s += item.split('|').join('</td><td>')
|
148
|
+
end
|
149
|
+
|
150
|
+
line_index += 1
|
151
|
+
end
|
152
|
+
block = "<table class=\"table\">#{s}</table>"
|
153
|
+
|
154
|
+
when /^[-]/
|
155
|
+
block = list(block.split("\n"))
|
156
|
+
|
157
|
+
when /^http[:][\/][\/]/
|
158
|
+
block = "<a href='#{block}'>#{block}</a><br />"
|
159
|
+
|
160
|
+
when /^https[:][\/][\/]/
|
161
|
+
block = "<a href='#{block}'>#{block}</a><br />"
|
162
|
+
|
163
|
+
else
|
164
|
+
block = self.inline_to_html_from_block(block)
|
165
|
+
block = block + "<br />" unless block == ""
|
166
|
+
end
|
167
|
+
|
168
|
+
block
|
169
|
+
end
|
170
|
+
|
171
|
+
def list(s_arr)
|
172
|
+
s_arr << ""
|
173
|
+
list_arr = []
|
174
|
+
s = ""
|
175
|
+
s_arr.each do |item|
|
176
|
+
if item.length > 0 && item.index("--") == 0
|
177
|
+
list_arr << item[1..item.length-1]
|
178
|
+
elsif item.length > 0 && item.index("-") == 0
|
179
|
+
if list_arr.length > 0
|
180
|
+
child_list = list(list_arr)
|
181
|
+
list_arr = []
|
182
|
+
else
|
183
|
+
child_list = ""
|
184
|
+
end
|
185
|
+
|
186
|
+
line = generate_contents(item[1..item.length])
|
187
|
+
if !child_list.blank?
|
188
|
+
s += "#{child_list}</li><li>#{line}"
|
189
|
+
else
|
190
|
+
s += "<li>#{line}"
|
191
|
+
end
|
192
|
+
|
193
|
+
else
|
194
|
+
if list_arr.length > 0
|
195
|
+
child_list = list(list_arr)
|
196
|
+
s += "#{child_list}"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
s = s + "</li>" if !s.blank?
|
201
|
+
s = generate_contents(s)
|
202
|
+
"<ul class=\"wikiUl\">#{s}</ul>".gsub('<br />', '')
|
203
|
+
end
|
204
|
+
|
205
|
+
def inline_to_html(parsed_block)
|
206
|
+
command = parsed_block[0]
|
207
|
+
result = ''
|
208
|
+
|
209
|
+
case command
|
210
|
+
when 'link'
|
211
|
+
link = parsed_block[1]
|
212
|
+
title = parsed_block[1]
|
213
|
+
if parsed_block.length > 2
|
214
|
+
title = parsed_block[2..parsed_block.length-1].join(" ")
|
215
|
+
end
|
216
|
+
|
217
|
+
result = "<a href='" + link + "'>" + title + "</a>"
|
218
|
+
when "code"
|
219
|
+
text = parsed_block[1..parsed_block.length-1].join(" ")
|
220
|
+
result = "<div style=\"margin: 0 1em;\"><pre class=\"prettyprint\">" + text + "</pre></div>"
|
221
|
+
#p parsed_block
|
222
|
+
when "pcode"
|
223
|
+
text = parsed_block[1..parsed_block.length-1].join(" ")
|
224
|
+
result = "<div style=\"margin: 0 1em;\"><pre style=\"font-family:sans-serif;\" class=\"prettyprint\">" + text + "</pre></div>"
|
225
|
+
when "b"
|
226
|
+
url = parsed_block[1]
|
227
|
+
quote = parsed_block[2..parsed_block.length-1].join(" ")
|
228
|
+
result = "<div class='blockquote'><blockquote cite='#{url}'><p class='bq'>#{quote}</p><cite><a href='#{url}'>#{url}</a></cite></blockquote></div>"
|
229
|
+
when "image_url"
|
230
|
+
url = parsed_block[1]
|
231
|
+
result = "<img src=\"#{url}\" />"
|
232
|
+
|
233
|
+
when "game"
|
234
|
+
id = parsed_block[1]
|
235
|
+
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
|
236
|
+
text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
|
237
|
+
url = "http://#{DOMAIN}/games/#{id}/play"
|
238
|
+
result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
|
239
|
+
|
240
|
+
when "open_game_form"
|
241
|
+
id = parsed_block[1]
|
242
|
+
text = parsed_block[2] ? parsed_block[2] : nil
|
243
|
+
submit_label = parsed_block[3] ? parsed_block[3..parsed_block.length-1] : nil
|
244
|
+
if text.blank?
|
245
|
+
text = "パラメータ"
|
246
|
+
end
|
247
|
+
|
248
|
+
if submit_label.blank?
|
249
|
+
submit_label = "ゲームを開く"
|
250
|
+
end
|
251
|
+
url = "http://#{DOMAIN}/games/#{id}/play"
|
252
|
+
result = <<-EOS
|
253
|
+
<form method="get" action="#{url}">
|
254
|
+
#{text}
|
255
|
+
<input type="text" name="gd" maxlength="200" size=20 />
|
256
|
+
<input type="submit" value="#{submit_label}" />
|
257
|
+
</form>
|
258
|
+
EOS
|
259
|
+
|
260
|
+
|
261
|
+
when "item"
|
262
|
+
id = parsed_block[1]
|
263
|
+
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
|
264
|
+
text = text ? text.join(" ") : "素材/ゲームデータ[ID:#{id}]"
|
265
|
+
url = "http://#{DOMAIN}/published_items/#{id}"
|
266
|
+
result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
|
267
|
+
|
268
|
+
when "wiki"
|
269
|
+
text = parsed_block[1..parsed_block.length-1].join(" ")
|
270
|
+
url = "http://page.#{DOMAIN}/a/" + text
|
271
|
+
result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
|
272
|
+
|
273
|
+
when "jump_target"
|
274
|
+
text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
|
275
|
+
result = "<a name=\"#{text.join}\"></a>"
|
276
|
+
|
277
|
+
when "jump"
|
278
|
+
link = parsed_block[1]
|
279
|
+
title = parsed_block[1]
|
280
|
+
if parsed_block.length > 2
|
281
|
+
title = parsed_block[2..parsed_block.length-1].join(" ")
|
282
|
+
end
|
283
|
+
|
284
|
+
result = "<a href=\"##{link}\">" + title + "</a>"
|
285
|
+
|
286
|
+
when "strike"
|
287
|
+
text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
|
288
|
+
result = "<span style=\"text-decoration:line-through;\">#{text}</span>"
|
289
|
+
|
290
|
+
when "bold"
|
291
|
+
text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
|
292
|
+
result = "<span style=\"font-weight:bold;\">#{text}</span>"
|
293
|
+
|
294
|
+
when "memo"
|
295
|
+
result = ""
|
296
|
+
|
297
|
+
when "font"
|
298
|
+
tags = parsed_block[1] ? parsed_block[1].split("_") : []
|
299
|
+
style = ""
|
300
|
+
tags.each do |tag|
|
301
|
+
if tag == "bold"
|
302
|
+
style += "font-weight:bold;"
|
303
|
+
elsif tag == "italic"
|
304
|
+
style += "font-style: italic;"
|
305
|
+
elsif tag == "strike"
|
306
|
+
style += "text-decoration:line-through;"
|
307
|
+
elsif ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"].include?(tag)
|
308
|
+
style += "font-size:#{tag};"
|
309
|
+
else
|
310
|
+
style += "color:#{tag};"
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
|
315
|
+
result = "<span style=\"#{style}\">#{text}</span>"
|
316
|
+
|
317
|
+
when "nicovideo"
|
318
|
+
id = parsed_block[1]
|
319
|
+
result = <<-EOS
|
320
|
+
<script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/#{id}?w=490&h=307"></script>
|
321
|
+
<noscript>JavaScriptが動いていないため、動画埋め込みが動作していません。</noscript>
|
322
|
+
EOS
|
323
|
+
|
324
|
+
when "youtube"
|
325
|
+
id = parsed_block[1]
|
326
|
+
result = <<-EOS
|
327
|
+
<iframe width="425" height="349" src="http://www.youtube.com/embed/#{id}"
|
328
|
+
frameborder="0" allowfullscreen></iframe>
|
329
|
+
EOS
|
330
|
+
|
331
|
+
when "game_player"
|
332
|
+
id = parsed_block[1]
|
333
|
+
@wiki_module_game_embed ||= false
|
334
|
+
unless @wiki_module_game_embed
|
335
|
+
result = "<script charset=\"utf-8\" src=\"http://rmake.jp/gadget/#{id.to_i}/js\"></script>"
|
336
|
+
@wiki_module_game_embed = true
|
337
|
+
else
|
338
|
+
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
|
339
|
+
text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
|
340
|
+
url = "http://#{DOMAIN}/games/#{id}/play"
|
341
|
+
result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
|
342
|
+
end
|
343
|
+
|
344
|
+
else
|
345
|
+
|
346
|
+
result = execute_plugins(command, parsed_block)
|
347
|
+
if result
|
348
|
+
|
349
|
+
else
|
350
|
+
result = "[" + parsed_block.join(" ") + "]"
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
result
|
355
|
+
rescue => err
|
356
|
+
"<div style=\"color:red;font-weight:bold;\">記述に間違いがあります: [" + parsed_block.join(" ") + "]</div>"
|
357
|
+
end
|
358
|
+
|
359
|
+
def execute_plugins(command, parsed_block)
|
360
|
+
result = false
|
361
|
+
|
362
|
+
@plugins ||= []
|
363
|
+
@plugins.each do |plugin|
|
364
|
+
if plugin.target?(command)
|
365
|
+
result = plugin.execute(command, parsed_block)
|
366
|
+
break
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
result
|
371
|
+
rescue => err
|
372
|
+
parsed_block << "{{プラグインのエラー}}"
|
373
|
+
end
|
374
|
+
|
375
|
+
def inline_to_html_from_block(block)
|
376
|
+
block.gsub!(/[\[].*?[\]]/) {|s|
|
377
|
+
s = self.inline_to_html(self.parse_inline(s))
|
378
|
+
}
|
379
|
+
|
380
|
+
block
|
381
|
+
end
|
382
|
+
|
383
|
+
def parse_inline(content)
|
384
|
+
content[1..content.length-2].sub(/([ ]|\n|\r\n|\r)/, " ").split(/[ ]/)
|
385
|
+
end
|
386
|
+
|
387
|
+
end
|
data/lib/rmake-util.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmake-notation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -36,6 +36,7 @@ extra_rdoc_files: []
|
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
38
|
- Gemfile
|
39
|
+
- MIT-LICENSE
|
39
40
|
- README.md
|
40
41
|
- Rakefile
|
41
42
|
- lib/rmake-notation.rb
|