rmake-notation 0.0.1

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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rmake-notation.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ rmake-notation
2
+ ==============
3
+
4
+ Rmakeで利用しているWiki記法「Rmake記法」を実現するためのgemです。
5
+
6
+ - [ゲームを作成して共有するサイト - Rmake](http://rmake.jp/)
7
+ - [Rmake記法の紹介とデモサイトはこちら](http://rmake-notation.herokuapp.com/)
8
+ - [サンプルアプリのリポジトリはこちらです](https://github.com/akasata/rmake-notation-samples)
9
+
10
+ ## SYSTEM REQUIREMENTS
11
+
12
+ - Ruby 1.9.3+
13
+
14
+ Windows環境の方は以下のパッケージを利用するといいでしょう。
15
+
16
+ - [ActiveScriptRuby and Other packages](http://www.artonx.org/data/asr/)
17
+
18
+ ## INSTALLATION
19
+
20
+ Gemをインストールして使ってください。
21
+
22
+ $ gem install rmake-notation
23
+
24
+ ## TODO
25
+
26
+ - specを書く(それに伴いテストしやすい構造に変更する)
27
+ - サンプルサイトの例を完全にする
28
+ - バグを取る
29
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,341 @@
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 to_blocks(content)
28
+ contents = Array.new
29
+ # content.gsub(/(^[|].*?(\n)[^|])|(^[-].*?(?=((^[^-])|\z)))|(^[{][{][{].*?[}][}][}])|(^[\[].*?[\]])|(^[!]*.*?$)|(^http[:][\/][\/])|(?!^).*?$/m) {|s|
30
+ content.gsub(/(^[|][|][|].*?[|][|][|])|(^[|].*?(?=(^[^|]|\z)))|(^[-].*?(?=((^[^-])|\z)))|(^[{][{][{].*?[}][}][}])|([\[].*?[\]])|(^[!]*.*?$)|(^http[:][\/][\/])|(?!^).*?$/m) {|s|
31
+ contents << s
32
+ }
33
+ contents
34
+ end
35
+
36
+ def process_table_line(block)
37
+ header = true
38
+ style = ""
39
+ tag = "td style=\"#{style}\""
40
+ code_reg = /[{][{][{].*?[}][}][}]/m
41
+
42
+ pcodes = []
43
+ block_text = block
44
+ pcode_count = 0
45
+ while block_text.index(code_reg)
46
+ pcodes << self.generate_contents(block_text.slice(code_reg))
47
+ block_text = block_text.sub(code_reg, "___dummy_pcodes___")
48
+
49
+ pcode_count += 1
50
+ end
51
+
52
+ s_arr = block_text.split("\n")
53
+ s = ""
54
+ line_index = 0
55
+ temp_item = ""
56
+
57
+ s_arr.each do |item|
58
+ temp_item += item
59
+
60
+ if item.index("|||") == 0
61
+ temp_item = ""
62
+ if item.index("header:none")
63
+ header = false
64
+ end
65
+
66
+ elsif temp_item.rindex(/[|]/).to_i == temp_item.length - 2
67
+ item = temp_item
68
+
69
+ if line_index == 0 && header
70
+ tag = "th style=\"#{style}\""
71
+ end
72
+
73
+ item = "<tr><#{tag}>" + item[item.index('|') + 1..item.rindex('|') - 1] + "</#{tag}></tr>"
74
+
75
+ items_before = item.split('|')
76
+ items_after = []
77
+ items_before.each do |before|
78
+ items_after << self.generate_contents(before).gsub("<br />", "")
79
+ end
80
+
81
+ s += items_after.join("</#{tag}><#{tag}>")
82
+
83
+ line_index += 1
84
+ temp_item = ""
85
+ tag = "td style=\"#{style}\""
86
+ end
87
+
88
+ end
89
+
90
+ pcodes.each do |pcode|
91
+ s = s.sub("___dummy_pcodes___", pcode)
92
+ end
93
+
94
+ block = "<table class=\"table\">#{s}</table>"
95
+ end
96
+
97
+ def block_to_html(block)
98
+ case block
99
+ when /\A[\[]/
100
+ parsed_block = self.parse_inline(block)
101
+ block = self.inline_to_html(parsed_block)
102
+ when /(\A[{][{][{])/
103
+ parsed_block = self.parse_inline(block.gsub("{{{", "[").gsub("}}}", "]"))
104
+ block = self.inline_to_html(parsed_block)
105
+ when /^[!]/
106
+ len = block.length - block.gsub!(/^[!]*/, "").length + 2
107
+ s = generate_contents(block)
108
+ block = "<h#{len}>#{s}</h#{len}>"
109
+
110
+ when /^[|][|][|]/
111
+ block = self.process_table_line(block)
112
+
113
+ when /^[|]/
114
+ s_arr = block.split("\n")
115
+ #s_arr.pop
116
+ s = ""
117
+ line_index = 0
118
+ s_arr.each do |item|
119
+ if line_index == 0
120
+ item = '<tr><th>' + item[item.index('|') + 1..item.rindex('|') - 1] + '</th></tr>'
121
+ s += item.split('|').join('</th><th>')
122
+ else
123
+ item = '<tr><td>' + item[item.index('|') + 1..item.rindex('|') - 1] + '</td></tr>'
124
+ s += item.split('|').join('</td><td>')
125
+ end
126
+
127
+ line_index += 1
128
+ end
129
+ block = "<table class=\"table\">#{s}</table>"
130
+
131
+ when /^[-]/
132
+ block = list(block.split("\n"))
133
+
134
+ when /^http[:][\/][\/]/
135
+ block = "<a href='#{block}'>#{block}</a><br />"
136
+
137
+ else
138
+ block = self.inline_to_html_from_block(block)
139
+ block = block + "<br />" unless block == ""
140
+ p block
141
+ end
142
+
143
+ block
144
+ end
145
+
146
+ def list(s_arr)
147
+ s_arr << ""
148
+ list_arr = []
149
+ s = ""
150
+ s_arr.each do |item|
151
+ if item.length > 0 && item.index("--") == 0
152
+ list_arr << item[1..item.length-1]
153
+ elsif item.length > 0 && item.index("-") == 0
154
+ if list_arr.length > 0
155
+ child_list = list(list_arr)
156
+ list_arr = []
157
+ else
158
+ child_list = ""
159
+ end
160
+
161
+ line = generate_contents(item[1..item.length])
162
+ if !child_list.blank?
163
+ s += "#{child_list}</li><li>#{line}"
164
+ else
165
+ s += "<li>#{line}"
166
+ end
167
+
168
+ else
169
+ if list_arr.length > 0
170
+ child_list = list(list_arr)
171
+ s += "#{child_list}"
172
+ end
173
+ end
174
+ end
175
+ s = s + "</li>" if !s.blank?
176
+ s = generate_contents(s)
177
+ "<ul class=\"wikiUl\">#{s}</ul>".gsub('<br />', '')
178
+ end
179
+
180
+ def inline_to_html(parsed_block)
181
+ command = parsed_block[0]
182
+ result = ''
183
+
184
+ case command
185
+ when 'link'
186
+ link = parsed_block[1]
187
+ title = parsed_block[1]
188
+ if parsed_block.length > 2
189
+ title = parsed_block[2..parsed_block.length-1].join(" ")
190
+ end
191
+
192
+ result = "<a href='" + link + "'>" + title + "</a>"
193
+ when "code"
194
+ text = parsed_block[1..parsed_block.length-1].join(" ")
195
+ result = "<div style=\"margin: 0 1em;\"><pre class=\"prettyprint\">" + text + "</pre></div>"
196
+ #p parsed_block
197
+ when "pcode"
198
+ text = parsed_block[1..parsed_block.length-1].join(" ")
199
+ result = "<div style=\"margin: 0 1em;\"><pre style=\"font-family:sans-serif;\" class=\"prettyprint\">" + text + "</pre></div>"
200
+ when "b"
201
+ url = parsed_block[1]
202
+ quote = parsed_block[2..parsed_block.length-1].join(" ")
203
+ result = "<div class='blockquote'><blockquote cite='#{url}'><p class='bq'>#{quote}</p><cite><a href='#{url}'>#{url}</a></cite></blockquote></div>"
204
+ when "image_url"
205
+ url = parsed_block[1]
206
+ result = "<img src=\"#{url}\" />"
207
+
208
+ when "game"
209
+ id = parsed_block[1]
210
+ text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
211
+ text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
212
+ url = "http://#{DOMAIN}/games/#{id}/play"
213
+ result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
214
+
215
+ when "open_game_form"
216
+ id = parsed_block[1]
217
+ text = parsed_block[2] ? parsed_block[2] : nil
218
+ submit_label = parsed_block[3] ? parsed_block[3..parsed_block.length-1] : nil
219
+ if text.blank?
220
+ text = "パラメータ"
221
+ end
222
+
223
+ if submit_label.blank?
224
+ submit_label = "ゲームを開く"
225
+ end
226
+ url = "http://#{DOMAIN}/games/#{id}/play"
227
+ result = <<-EOS
228
+ <form method="get" action="#{url}">
229
+ #{text}
230
+ <input type="text" name="gd" maxlength="200" size=20 />
231
+ <input type="submit" value="#{submit_label}" />
232
+ </form>
233
+ EOS
234
+
235
+
236
+ when "item"
237
+ id = parsed_block[1]
238
+ text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
239
+ text = text ? text.join(" ") : "素材/ゲームデータ[ID:#{id}]"
240
+ url = "http://#{DOMAIN}/published_items/#{id}"
241
+ result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
242
+
243
+ when "wiki"
244
+ text = parsed_block[1..parsed_block.length-1].join(" ")
245
+ url = "http://page.#{DOMAIN}/a/" + text
246
+ result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
247
+
248
+ when "jump_target"
249
+ text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
250
+ result = "<a name=\"#{text.join}\"></a>"
251
+
252
+ when "jump"
253
+ link = parsed_block[1]
254
+ title = parsed_block[1]
255
+ if parsed_block.length > 2
256
+ title = parsed_block[2..parsed_block.length-1].join(" ")
257
+ end
258
+
259
+ result = "<a href=\"##{link}\">" + title + "</a>"
260
+
261
+ when "strike"
262
+ text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
263
+ result = "<span style=\"text-decoration:line-through;\">#{text}</span>"
264
+
265
+ when "bold"
266
+ text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
267
+ result = "<span style=\"font-weight:bold;\">#{text}</span>"
268
+
269
+ when "memo"
270
+ result = ""
271
+
272
+ when "font"
273
+ tags = parsed_block[1] ? parsed_block[1].split("_") : []
274
+ style = ""
275
+ tags.each do |tag|
276
+ if tag == "bold"
277
+ style += "font-weight:bold;"
278
+ elsif tag == "italic"
279
+ style += "font-style: italic;"
280
+ elsif tag == "strike"
281
+ style += "text-decoration:line-through;"
282
+ elsif ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"].include?(tag)
283
+ style += "font-size:#{tag};"
284
+ else
285
+ style += "color:#{tag};"
286
+ end
287
+ end
288
+
289
+ text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
290
+ result = "<span style=\"#{style}\">#{text}</span>"
291
+
292
+ when "nicovideo"
293
+ id = parsed_block[1]
294
+ result = <<-EOS
295
+ <script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/#{id}?w=490&h=307"></script>
296
+ <noscript>JavaScriptが動いていないため、動画埋め込みが動作していません。</noscript>
297
+ EOS
298
+
299
+ when "youtube"
300
+ id = parsed_block[1]
301
+ result = <<-EOS
302
+ <iframe width="425" height="349" src="http://www.youtube.com/embed/#{id}"
303
+ frameborder="0" allowfullscreen></iframe>
304
+ EOS
305
+
306
+ when "game_player"
307
+ id = parsed_block[1]
308
+ @wiki_module_game_embed ||= false
309
+ unless @wiki_module_game_embed
310
+ result = "<script charset=\"utf-8\" src=\"http://rmake.jp/gadget/#{id.to_i}/js\"></script>"
311
+ @wiki_module_game_embed = true
312
+ else
313
+ text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
314
+ text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
315
+ url = "http://#{DOMAIN}/games/#{id}/play"
316
+ result = "<a href=\"#{url}\" title=\"#{text}\">#{text}</a>"
317
+ end
318
+
319
+ else
320
+ result = "[" + parsed_block.join(" ") + "]"
321
+ result
322
+ end
323
+
324
+ result
325
+ rescue => err
326
+ "<div style=\"color:red;font-weight:bold;\">記述に間違いがあります: [" + parsed_block.join(" ") + "]</div>"
327
+ end
328
+
329
+ def inline_to_html_from_block(block)
330
+ block.gsub!(/[\[].*?[\]]/) {|s|
331
+ s = self.inline_to_html(self.parse_inline(s))
332
+ }
333
+
334
+ block
335
+ end
336
+
337
+ def parse_inline(content)
338
+ content[1..content.length-2].sub(/([ ]|\n|\r\n|\r)/, " ").split(/[ ]/)
339
+ end
340
+
341
+ end
@@ -0,0 +1,5 @@
1
+ module Rmake
2
+ module Notation
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/rmake-util.rb ADDED
@@ -0,0 +1,49 @@
1
+ # util.rb is inspired by ActiveSupport
2
+
3
+ class Object
4
+ def blank?
5
+ respond_to?(:empty?) ? empty? : !self
6
+ end
7
+ end
8
+
9
+ class NilClass
10
+ def blank?
11
+ true
12
+ end
13
+ end
14
+
15
+ class FalseClass
16
+ def blank?
17
+ true
18
+ end
19
+ end
20
+
21
+ class TrueClass
22
+ def blank?
23
+ false
24
+ end
25
+ end
26
+
27
+ class Array
28
+ alias_method :blank?, :empty?
29
+ end
30
+
31
+ class Hash
32
+ alias_method :blank?, :empty?
33
+ end
34
+
35
+ class String
36
+ def blank?
37
+ self !~ /[^[:space:]]/
38
+ end
39
+ end
40
+
41
+ class Numeric #:nodoc:
42
+ def blank?
43
+ false
44
+ end
45
+ end
46
+
47
+ module Rmake::Util
48
+ end
49
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rmake-notation/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["akasata", "Rmake Co., Ltd."]
6
+ gem.email = ["akasata@rmake.net"]
7
+ gem.description = %q{A simple wiki engine for Rmake. }
8
+ gem.summary = %q{A simple wiki engine}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "rmake-notation"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Rmake::Notation::VERSION
17
+
18
+ gem.add_development_dependency('rspec')
19
+ end
20
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rmake-notation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - akasata
9
+ - Rmake Co., Ltd.
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-02-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ description: ! 'A simple wiki engine for Rmake. '
32
+ email:
33
+ - akasata@rmake.net
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - lib/rmake-notation.rb
44
+ - lib/rmake-notation/version.rb
45
+ - lib/rmake-util.rb
46
+ - rmake-notation.gemspec
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.25
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A simple wiki engine
71
+ test_files: []