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 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
@@ -1,5 +1,5 @@
1
1
  module Rmake
2
2
  module Notation
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -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
- result = ''
11
- blocks = self.to_blocks(content)
12
-
13
- blocks.each do |b|
14
- block = self.block_to_html(b)
15
- result += block
16
- end
17
-
18
- #result += " ********** " + blocks.join(",")
19
- result.gsub("-)", "]")
20
-
21
- rescue => err
22
- message = err.message + "\n"
23
- message += err.backtrace.join("\n")
24
- message += "文章にエラーもしくは不正な文字が含まれているようです。確認してください。"
25
- end
26
-
27
- def add_plugin(plugin)
28
- @plugins ||= []
29
-
30
- if (plugin.respond_to?(:target?) && plugin.respond_to?(:execute))
31
- @plugins << plugin
32
- true
33
- else
34
- false
35
- end
36
- end
37
-
38
- def to_blocks(content)
39
- contents = Array.new
40
- # content.gsub(/(^[|].*?(\n)[^|])|(^[-].*?(?=((^[^-])|\z)))|(^[{][{][{].*?[}][}][}])|(^[\[].*?[\]])|(^[!]*.*?$)|(^http[:][\/][\/])|(?!^).*?$/m) {|s|
41
- content.gsub(/(^[|][|][|].*?[|][|][|])|(^[|].*?(?=(^[^|]|\z)))|(^[-].*?(?=((^[^-])|\z)))|(^[{][{][{].*?[}][}][}])|([\[].*?[\]])|(^[!]*.*?$)|(^http[:][\/][\/])|(?!^).*?$/m) {|s|
42
- contents << s
43
- }
44
- contents
45
- end
46
-
47
- def process_table_line(block)
48
- header = true
49
- style = ""
50
- tag = "td style=\"#{style}\""
51
- code_reg = /[{][{][{].*?[}][}][}]/m
52
-
53
- pcodes = []
54
- block_text = block
55
- pcode_count = 0
56
- while block_text.index(code_reg)
57
- pcodes << self.generate_contents(block_text.slice(code_reg))
58
- block_text = block_text.sub(code_reg, "___dummy_pcodes___")
59
-
60
- pcode_count += 1
61
- end
62
-
63
- s_arr = block_text.split("\n")
64
- s = ""
65
- line_index = 0
66
- temp_item = ""
67
-
68
- s_arr.each do |item|
69
- temp_item += item
70
-
71
- if item.index("|||") == 0
72
- temp_item = ""
73
- if item.index("header:none")
74
- header = false
75
- end
76
-
77
- elsif temp_item.rindex(/[|]/).to_i == temp_item.length - 2
78
- item = temp_item
79
-
80
- if line_index == 0 && header
81
- tag = "th style=\"#{style}\""
82
- end
83
-
84
- item = "<tr><#{tag}>" + item[item.index('|') + 1..item.rindex('|') - 1] + "</#{tag}></tr>"
85
-
86
- items_before = item.split('|')
87
- items_after = []
88
- items_before.each do |before|
89
- items_after << self.generate_contents(before).gsub("<br />", "")
90
- end
91
-
92
- s += items_after.join("</#{tag}><#{tag}>")
93
-
94
- line_index += 1
95
- temp_item = ""
96
- tag = "td style=\"#{style}\""
97
- end
98
-
99
- end
100
-
101
- pcodes.each do |pcode|
102
- s = s.sub("___dummy_pcodes___", pcode)
103
- end
104
-
105
- block = "<table class=\"table\">#{s}</table>"
106
- end
107
-
108
- def block_to_html(block)
109
- case block
110
- when /\A[\[]/
111
- parsed_block = self.parse_inline(block)
112
- block = self.inline_to_html(parsed_block)
113
- when /(\A[{][{][{])/
114
- parsed_block = self.parse_inline(block.gsub("{{{", "[").gsub("}}}", "]"))
115
- block = self.inline_to_html(parsed_block)
116
- when /^[!]/
117
- len = block.length - block.gsub!(/^[!]*/, "").length + 2
118
- s = generate_contents(block)
119
- block = "<h#{len}>#{s}</h#{len}>"
120
-
121
- when /^[|][|][|]/
122
- block = self.process_table_line(block)
123
-
124
- when /^[|]/
125
- s_arr = block.split("\n")
126
- #s_arr.pop
127
- s = ""
128
- line_index = 0
129
- s_arr.each do |item|
130
- if line_index == 0
131
- item = '<tr><th>' + item[item.index('|') + 1..item.rindex('|') - 1] + '</th></tr>'
132
- s += item.split('|').join('</th><th>')
133
- else
134
- item = '<tr><td>' + item[item.index('|') + 1..item.rindex('|') - 1] + '</td></tr>'
135
- s += item.split('|').join('</td><td>')
136
- end
137
-
138
- line_index += 1
139
- end
140
- block = "<table class=\"table\">#{s}</table>"
141
-
142
- when /^[-]/
143
- block = list(block.split("\n"))
144
-
145
- when /^http[:][\/][\/]/
146
- block = "<a href='#{block}'>#{block}</a><br />"
147
-
148
- else
149
- block = self.inline_to_html_from_block(block)
150
- block = block + "<br />" unless block == ""
151
- p block
152
- end
153
-
154
- block
155
- end
156
-
157
- def list(s_arr)
158
- s_arr << ""
159
- list_arr = []
160
- s = ""
161
- s_arr.each do |item|
162
- if item.length > 0 && item.index("--") == 0
163
- list_arr << item[1..item.length-1]
164
- elsif item.length > 0 && item.index("-") == 0
165
- if list_arr.length > 0
166
- child_list = list(list_arr)
167
- list_arr = []
168
- else
169
- child_list = ""
170
- end
171
-
172
- line = generate_contents(item[1..item.length])
173
- if !child_list.blank?
174
- s += "#{child_list}</li><li>#{line}"
175
- else
176
- s += "<li>#{line}"
177
- end
178
-
179
- else
180
- if list_arr.length > 0
181
- child_list = list(list_arr)
182
- s += "#{child_list}"
183
- end
184
- end
185
- end
186
- s = s + "</li>" if !s.blank?
187
- s = generate_contents(s)
188
- "<ul class=\"wikiUl\">#{s}</ul>".gsub('<br />', '')
189
- end
190
-
191
- def inline_to_html(parsed_block)
192
- command = parsed_block[0]
193
- result = ''
194
-
195
- case command
196
- when 'link'
197
- link = parsed_block[1]
198
- title = parsed_block[1]
199
- if parsed_block.length > 2
200
- title = parsed_block[2..parsed_block.length-1].join(" ")
201
- end
202
-
203
- result = "<a href='" + link + "'>" + title + "</a>"
204
- when "code"
205
- text = parsed_block[1..parsed_block.length-1].join(" ")
206
- result = "<div style=\"margin: 0 1em;\"><pre class=\"prettyprint\">" + text + "</pre></div>"
207
- #p parsed_block
208
- when "pcode"
209
- text = parsed_block[1..parsed_block.length-1].join(" ")
210
- result = "<div style=\"margin: 0 1em;\"><pre style=\"font-family:sans-serif;\" class=\"prettyprint\">" + text + "</pre></div>"
211
- when "b"
212
- url = parsed_block[1]
213
- quote = parsed_block[2..parsed_block.length-1].join(" ")
214
- result = "<div class='blockquote'><blockquote cite='#{url}'><p class='bq'>#{quote}</p><cite><a href='#{url}'>#{url}</a></cite></blockquote></div>"
215
- when "image_url"
216
- url = parsed_block[1]
217
- result = "<img src=\"#{url}\" />"
218
-
219
- when "game"
220
- id = parsed_block[1]
221
- text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
222
- text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
223
- url = "http://#{DOMAIN}/games/#{id}/play"
224
- result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
225
-
226
- when "open_game_form"
227
- id = parsed_block[1]
228
- text = parsed_block[2] ? parsed_block[2] : nil
229
- submit_label = parsed_block[3] ? parsed_block[3..parsed_block.length-1] : nil
230
- if text.blank?
231
- text = "パラメータ"
232
- end
233
-
234
- if submit_label.blank?
235
- submit_label = "ゲームを開く"
236
- end
237
- url = "http://#{DOMAIN}/games/#{id}/play"
238
- result = <<-EOS
239
- <form method="get" action="#{url}">
240
- #{text}
241
- <input type="text" name="gd" maxlength="200" size=20 />
242
- <input type="submit" value="#{submit_label}" />
243
- </form>
244
- EOS
245
-
246
-
247
- when "item"
248
- id = parsed_block[1]
249
- text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
250
- text = text ? text.join(" ") : "素材/ゲームデータ[ID:#{id}]"
251
- url = "http://#{DOMAIN}/published_items/#{id}"
252
- result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
253
-
254
- when "wiki"
255
- text = parsed_block[1..parsed_block.length-1].join(" ")
256
- url = "http://page.#{DOMAIN}/a/" + text
257
- result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
258
-
259
- when "jump_target"
260
- text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
261
- result = "<a name=\"#{text.join}\"></a>"
262
-
263
- when "jump"
264
- link = parsed_block[1]
265
- title = parsed_block[1]
266
- if parsed_block.length > 2
267
- title = parsed_block[2..parsed_block.length-1].join(" ")
268
- end
269
-
270
- result = "<a href=\"##{link}\">" + title + "</a>"
271
-
272
- when "strike"
273
- text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
274
- result = "<span style=\"text-decoration:line-through;\">#{text}</span>"
275
-
276
- when "bold"
277
- text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
278
- result = "<span style=\"font-weight:bold;\">#{text}</span>"
279
-
280
- when "memo"
281
- result = ""
282
-
283
- when "font"
284
- tags = parsed_block[1] ? parsed_block[1].split("_") : []
285
- style = ""
286
- tags.each do |tag|
287
- if tag == "bold"
288
- style += "font-weight:bold;"
289
- elsif tag == "italic"
290
- style += "font-style: italic;"
291
- elsif tag == "strike"
292
- style += "text-decoration:line-through;"
293
- elsif ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"].include?(tag)
294
- style += "font-size:#{tag};"
295
- else
296
- style += "color:#{tag};"
297
- end
298
- end
299
-
300
- text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
301
- result = "<span style=\"#{style}\">#{text}</span>"
302
-
303
- when "nicovideo"
304
- id = parsed_block[1]
305
- result = <<-EOS
306
- <script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/#{id}?w=490&h=307"></script>
307
- <noscript>JavaScriptが動いていないため、動画埋め込みが動作していません。</noscript>
308
- EOS
309
-
310
- when "youtube"
311
- id = parsed_block[1]
312
- result = <<-EOS
313
- <iframe width="425" height="349" src="http://www.youtube.com/embed/#{id}"
314
- frameborder="0" allowfullscreen></iframe>
315
- EOS
316
-
317
- when "game_player"
318
- id = parsed_block[1]
319
- @wiki_module_game_embed ||= false
320
- unless @wiki_module_game_embed
321
- result = "<script charset=\"utf-8\" src=\"http://rmake.jp/gadget/#{id.to_i}/js\"></script>"
322
- @wiki_module_game_embed = true
323
- else
324
- text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
325
- text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
326
- url = "http://#{DOMAIN}/games/#{id}/play"
327
- result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
328
- end
329
-
330
- else
331
-
332
- result = execute_plugins(command, parsed_block)
333
- if result
334
-
335
- else
336
- result = "[" + parsed_block.join(" ") + "]"
337
- end
338
- end
339
-
340
- result
341
- rescue => err
342
- "<div style=\"color:red;font-weight:bold;\">記述に間違いがあります: [" + parsed_block.join(" ") + "]</div>"
343
- end
344
-
345
- def execute_plugins(command, parsed_block)
346
- result = false
347
-
348
- @plugins ||= []
349
- @plugins.each do |plugin|
350
- if plugin.target?(command)
351
- result = plugin.execute(command, parsed_block)
352
- break
353
- end
354
- end
355
-
356
- result
357
- rescue => err
358
- parsed_block << "{{プラグインのエラー}}"
359
- end
360
-
361
- def inline_to_html_from_block(block)
362
- block.gsub!(/[\[].*?[\]]/) {|s|
363
- s = self.inline_to_html(self.parse_inline(s))
364
- }
365
-
366
- block
367
- end
368
-
369
- def parse_inline(content)
370
- content[1..content.length-2].sub(/([ ]|\n|\r\n|\r)/, " ").split(/[ ]/)
371
- end
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
@@ -38,7 +38,7 @@ class String
38
38
  end
39
39
  end
40
40
 
41
- class Numeric #:nodoc:
41
+ class Numeric
42
42
  def blank?
43
43
  false
44
44
  end
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.2
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-02-22 00:00:00.000000000 Z
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