raf 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ef425f171fb1428d84f05600664075ccd486eb9
4
- data.tar.gz: 3a34f1507f9d623723aff59b15ce1e5998ef4b8e
3
+ metadata.gz: c185ed73d5d2fe3fed31aa048c256b458cdef61d
4
+ data.tar.gz: 0f728c67524f41bd3fa44adbd571b95444a24552
5
5
  SHA512:
6
- metadata.gz: cc6503f3a492c31334c8e3a9cf7f75b0fc8c21fdd6b71349e948fba1ad5b71aa23efcd69f0c1a2cf7b58dd798ef5134e37583a3f429d6f77adee2462f1f36c43
7
- data.tar.gz: 49c818d4053e7f257afb84e774b9cbebe22eba46b52c05e7f76dd5f8641d6e2a0fe3aff7040f349f3787175c682c3ee38c9ee3fe9e76a6c0e263aa8c369a6b60
6
+ metadata.gz: 6c264951405f105cf060dd463c45ef91a3cd2901fbae978ee1e913a1cb2b3d496d6d969b7008673ffcc052480b35f4c50734b1a8c7309eded18097b391fede3f
7
+ data.tar.gz: f588eecc9d45853a027822ca9034091f0965cf11419a40ff188fad8c2a32b5e925730169f2b5f2519aa6ad51901e390d7559586b0386d074ff525298bf9be62a
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
-
2
+ ruby '2.0.0'
3
3
  # Specify your gem's dependencies in raf.gemspec
4
4
  gemspec
data/README.rdoc CHANGED
@@ -2,14 +2,33 @@
2
2
  "raf" is simple document format.
3
3
  refer to : http://garin.jp/doc/raf/raf (this page is japanese)
4
4
 
5
- == install
5
+ == INSTALLATION
6
6
  // check ruby version
7
7
  $ ruby -v
8
8
  ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
9
9
 
10
- // raf gem package install
10
+ // raf gem package install
11
11
  $ gem install raf
12
12
 
13
+ == UTILITIES
14
+ === raf
15
+ print raf format version.
16
+
17
+ === raf2html
18
+ Raf format to HTML format conveter.
19
+
20
+ + Usage
21
+ // edit
22
+ $ vi mydoc.raf
23
+ = This is My document
24
+ raf is simple document format.
25
+
26
+ // to html
27
+ $ raf2html mydoc.raf > mydoc.html
28
+
29
+ == Read more
30
+ Official Web Site : http://garin.jp/doc/raf/raf (this page is japanese)
31
+
13
32
  == Copyright
14
33
  Copyright (c) 2011-2013 garin. See LICENSE.txt for
15
34
  further details.
data/RELEASE ADDED
@@ -0,0 +1 @@
1
+ 2013-11-26
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/raf ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (C) garin <garin54@gmail.com> 2011-2013
4
+ # See the included file COPYING for details.
5
+ $:.unshift File.join(File.dirname(__FILE__), "../lib")
6
+ require "raf"
7
+ require "optparse"
8
+
9
+ opt = OptionParser.new do |opt|
10
+ opt.version = Raf::VERSION
11
+ opt.release = Raf::RELEASE
12
+ opt.banner = <<EOL
13
+ "raf" is simple document format.
14
+ Read more: https://github.com/garin/raf
15
+ EOL
16
+ end
17
+
18
+ opt.parse!(ARGV)
19
+ puts opt.help
data/bin/raf2html CHANGED
@@ -1,15 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- encoding: utf-8 -*-
3
- # Copyright (C) garin <garin54@gmail.com> 2011
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (C) garin <garin54@gmail.com> 2011-2013
4
4
  # See the included file COPYING for details.
5
5
  $:.unshift File.join(File.dirname(__FILE__), "../lib")
6
6
  require "optparse"
7
7
  require "raf2html"
8
8
 
9
+ def usage(opt)
10
+ puts opt.help
11
+ exit 0
12
+ end
13
+
9
14
  options = {:css => nil, :language => 'ja', :index => true, :quiet => false}
10
15
  opt = OptionParser.new do |opt|
11
- opt.release = "2011-04-07"
12
- opt.version = "0.0.2"
16
+ opt.banner = "Usage: raf2html [options] file"
17
+ opt.version = Raf::Raf2Html::VERSION
18
+ opt.release = Raf::Raf2Html::RELEASE
13
19
  opt.on("--css file", "スタイルシートのファイルを指定") {|f| options[:css] = f}
14
20
  opt.on("-L", "--language LANG", "言語(デフォルトは #{options[:language]} 。ドキュメント側で指定されていればそちらを優先)"){|l| options[:language] = l}
15
21
  opt.on("--[no-]index", "目次を生成する(デフォルトは生成する)"){|v| options[:index] = v }
@@ -17,6 +23,7 @@ opt = OptionParser.new do |opt|
17
23
  opt.on("-q","--quiet", "本文だけを出力する(ヘッダやフッタは出力しない)"){ options[:quiet] = true }
18
24
  end
19
25
  opt.parse!(ARGV)
26
+ usage(opt) unless ARGV[0]
20
27
  src = File.open(ARGV[0],"r").readlines
21
28
  raf = Raf::Raf2Html.new(src, options)
22
29
  puts raf.to_html
data/lib/raf.rb ADDED
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) garin <garin54@gmail.com> 2011-2013
3
+ # See the included file COPYING for details.
4
+ module Raf
5
+ VERSION = File.readlines(File.join(File.dirname(__FILE__),"../VERSION"))[0].strip
6
+ RELEASE = File.readlines(File.join(File.dirname(__FILE__),"../RELEASE"))[0].strip
7
+ end
data/lib/raf2html.rb CHANGED
@@ -6,6 +6,9 @@ require "cgi"
6
6
 
7
7
  module Raf
8
8
  class Raf2Html
9
+ VERSION="0.0.2"
10
+ RELEASE="2011-04-07"
11
+
9
12
  def initialize(src, options = {})
10
13
  @debug = true
11
14
 
@@ -18,7 +21,7 @@ module Raf
18
21
 
19
22
  @raf = BlockParser.new
20
23
  @metadata = setup_metadata
21
- @nodes = @raf.parse src.map {|s| CGI.escapeHTML(s) }
24
+ @nodes = @raf.parse src
22
25
  end
23
26
 
24
27
  def setup_metadata
@@ -147,7 +147,7 @@ module Raf
147
147
 
148
148
  class Plain < Element
149
149
  def apply
150
- "#{newline_to_br(@contents.join(""))}"
150
+ "#{newline_to_br(CGI.escapeHTML(@contents.join))}"
151
151
  end
152
152
  end
153
153
 
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) garin <garin54@gmail.com> 2011
2
2
  # See the included file COPYING for details.
3
3
  class InlineParser
4
- token EM_OPEN EM_CLOSE ITALIC_OPEN ITALIC_CLOSE STRIKE_OPEN STRIKE_CLOSE LABEL_OPEN LABEL_CLOSE REFERENCE_OPEN REFERENCE_CLOSE VERB_OPEN VERB_CLOSE ERB_OPEN ERB_CLOSE FOOTNOTE_OPEN FOOTNOTE_CLOSE RUBY_OPEN RUBY_CLOSE IMAGE_OPEN IMAGE_CLOSE MANUEDO_OPEN MANUEDO_CLOSE BAR QUOTE SLASH BACK_SLASH OTHER
4
+ token EM_OPEN EM_CLOSE ITALIC_OPEN ITALIC_CLOSE STRIKE_OPEN STRIKE_CLOSE LABEL_OPEN LABEL_CLOSE REFERENCE_OPEN REFERENCE_CLOSE VERB_OPEN VERB_CLOSE ERB_OPEN ERB_CLOSE HERB_OPEN FOOTNOTE_OPEN FOOTNOTE_CLOSE RUBY_OPEN RUBY_CLOSE IMAGE_OPEN IMAGE_CLOSE MANUEDO_OPEN MANUEDO_CLOSE OTHER
5
5
  options no_result_var
6
6
  rule
7
7
  content :
@@ -10,7 +10,6 @@ class InlineParser
10
10
  elements : elements element { val[0].push(val[1]) }
11
11
  | element { val }
12
12
 
13
-
14
13
  element : emphasis
15
14
  | italic
16
15
  | strike
@@ -21,6 +20,7 @@ class InlineParser
21
20
  | image
22
21
  | verb
23
22
  | erb
23
+ | herb
24
24
  | manuedo
25
25
  | normal_strings
26
26
 
@@ -34,15 +34,10 @@ class InlineParser
34
34
  Footnote.new([val[1], @index[:footnote].size])
35
35
  }
36
36
 
37
-
38
37
  # --- inline end
39
38
 
40
39
  # --- image
41
40
  image_string : OTHER
42
- | QUOTE
43
- | BAR
44
- | SLASH
45
- | BACK_SLASH
46
41
  | EM_OPEN
47
42
  | EM_CLOSE
48
43
  | ITALIC_OPEN
@@ -55,6 +50,7 @@ class InlineParser
55
50
  | MANUEDO_CLOSE
56
51
  | ERB_OPEN
57
52
  | ERB_CLOSE
53
+ | HERB_OPEN
58
54
  | REFERENCE_OPEN
59
55
  | REFERENCE_CLOSE
60
56
  | LABEL_OPEN
@@ -72,10 +68,6 @@ class InlineParser
72
68
  # --- image end
73
69
  # --- ruby
74
70
  ruby_string : OTHER
75
- | QUOTE
76
- | BAR
77
- | SLASH
78
- | BACK_SLASH
79
71
  | EM_OPEN
80
72
  | EM_CLOSE
81
73
  | ITALIC_OPEN
@@ -88,6 +80,7 @@ class InlineParser
88
80
  | MANUEDO_CLOSE
89
81
  | ERB_OPEN
90
82
  | ERB_CLOSE
83
+ | HERB_OPEN
91
84
  | REFERENCE_OPEN
92
85
  | REFERENCE_CLOSE
93
86
  | LABEL_OPEN
@@ -112,6 +105,9 @@ class InlineParser
112
105
  erb : ERB_OPEN verb_string ERB_CLOSE {
113
106
  e = ERB.new("<%= #{val[1]} %>")
114
107
  Plain.new(e.result) }
108
+ herb : HERB_OPEN verb_string ERB_CLOSE {
109
+ e = ERB.new("<% #{val[1]} %>")
110
+ Plain.new(e.result) }
115
111
  # --- erb end
116
112
  # --- manuedo
117
113
  manuedo : MANUEDO_OPEN content MANUEDO_CLOSE { Manuedo.new(val[1]) }
@@ -120,10 +116,7 @@ class InlineParser
120
116
 
121
117
  # --- label
122
118
  label_string : OTHER { val[0] }
123
- | QUOTE { val[0] }
124
- | BAR { val[0] }
125
- | SLASH { val[0] }
126
- | BACK_SLASH { val[0] }
119
+
127
120
 
128
121
  label_strings : label_strings label_string { val.join }
129
122
  | label_string { val[0] }
@@ -139,10 +132,6 @@ class InlineParser
139
132
  # --- labe end
140
133
  # --- reference : start
141
134
  reference_string : OTHER { val[0] }
142
- | QUOTE { val[0] }
143
- | BAR { val[0] }
144
- | SLASH { val[0] }
145
- | BACK_SLASH { val[0] }
146
135
 
147
136
  reference_strings : reference_strings reference_string { val.join }
148
137
  | reference_string { val[0] }
@@ -156,10 +145,6 @@ class InlineParser
156
145
  # --- reference : end
157
146
  # --- verb
158
147
  verb_string : OTHER
159
- | QUOTE
160
- | BAR
161
- | SLASH
162
- | BACK_SLASH
163
148
  | EM_OPEN
164
149
  | EM_CLOSE
165
150
  | ITALIC_OPEN
@@ -172,6 +157,7 @@ class InlineParser
172
157
  | MANUEDO_CLOSE
173
158
  | ERB_OPEN
174
159
  | ERB_CLOSE
160
+ | HERB_OPEN
175
161
  | REFERENCE_OPEN
176
162
  | REFERENCE_CLOSE
177
163
  | LABEL_OPEN
@@ -193,10 +179,6 @@ class InlineParser
193
179
  | normal_strings normal_string { Plain.new([val[0].contents, val[1]]) }
194
180
 
195
181
  normal_string : OTHER { val[0] }
196
- | QUOTE { val[0] }
197
- | BAR { val[0] }
198
- | SLASH { val[0] }
199
- | BACK_SLASH { val[0] }
200
182
  # --- normal end
201
183
 
202
184
  ---- inner
@@ -232,7 +214,6 @@ IMAGE_OPEN_RE = /\A#{Regexp.quote(IMAGE_OPEN)}/
232
214
  IMAGE_CLOSE = '$))'
233
215
  IMAGE_CLOSE_RE = /\A#{Regexp.quote(IMAGE_CLOSE)}/
234
216
 
235
-
236
217
  LABEL_OPEN = '((>'
237
218
  LABEL_OPEN_RE = /\A#{Regexp.quote(LABEL_OPEN)}/
238
219
  LABEL_CLOSE = '<))'
@@ -243,15 +224,14 @@ LABEL_HTML_OPEN_RE = /\A#{Regexp.quote(LABEL_HTML_OPEN)}/
243
224
  LABEL_HTML_CLOSE = '&lt;))'
244
225
  LABEL_HTML_CLOSE_RE = /\A#{Regexp.quote(LABEL_HTML_CLOSE)}/
245
226
 
246
-
247
227
  REFERENCE_OPEN = '((<'
248
228
  REFERENCE_OPEN_RE = /\A#{Regexp.quote(REFERENCE_OPEN)}/
249
229
  REFERENCE_CLOSE = '>))'
250
230
  REFERENCE_CLOSE_RE = /\A#{Regexp.quote(REFERENCE_CLOSE)}/
251
231
 
252
- REFERENCE_HTML_OPEN = '((&lt;'
232
+ REFERENCE_HTML_OPEN = '((<'
253
233
  REFERENCE_HTML_OPEN_RE = /\A#{Regexp.quote(REFERENCE_HTML_OPEN)}/
254
- REFERENCE_HTML_CLOSE = '&gt;))'
234
+ REFERENCE_HTML_CLOSE = '>))'
255
235
  REFERENCE_HTML_CLOSE_RE = /\A#{Regexp.quote(REFERENCE_HTML_CLOSE)}/
256
236
 
257
237
  VERB_OPEN = "(('"
@@ -264,27 +244,21 @@ MANUEDO_OPEN_RE = /\A#{Regexp.quote(MANUEDO_OPEN)}/
264
244
  MANUEDO_CLOSE = "/))"
265
245
  MANUEDO_CLOSE_RE = /\A#{Regexp.quote(MANUEDO_CLOSE)}/
266
246
 
267
- ERB_OPEN = "&lt;%="
247
+ ERB_OPEN = "<%="
268
248
  ERB_OPEN_RE = /\A#{Regexp.quote(ERB_OPEN)}/
269
- ERB_CLOSE = "%&gt;"
249
+ ERB_CLOSE = "%>"
270
250
  ERB_CLOSE_RE = /\A#{Regexp.quote(ERB_CLOSE)}/
271
251
 
272
- BAR = "|"
273
- BAR_RE = /\A#{Regexp.quote(BAR)}/
274
- QUOTE = '"'
275
- QUOTE_RE = /\A#{Regexp.quote(QUOTE)}/
276
- SLASH = "/"
277
- SLASH_RE = /\A#{Regexp.quote(SLASH)}/
278
- BACK_SLASH = "\\"
279
- BACK_SLASH_RE = /\A#{Regexp.quote(BACK_SLASH)}/
252
+ HERB_OPEN = "<%"
253
+ HERB_OPEN_RE = /\A#{Regexp.quote(HERB_OPEN)}/
254
+
280
255
  # URL = "URL:"
281
256
  # URL_RE = /\A#{Regexp.quote(URL)}/
282
257
 
283
258
  #other_re_mode = Regexp::EXTENDED
284
259
  other_re_mode = Regexp::MULTILINE
285
260
  OTHER_RE = Regexp.new(
286
- "\\A.+?(?=#{Regexp.quote(EM_OPEN)}|#{Regexp.quote(EM_CLOSE)}|#{Regexp.quote(ITALIC_OPEN)}|#{Regexp.quote(ITALIC_CLOSE)}|#{Regexp.quote(STRIKE_OPEN)}|#{Regexp.quote(STRIKE_CLOSE)}|#{Regexp.quote(FOOTNOTE_OPEN)}|#{Regexp.quote(FOOTNOTE_CLOSE)}|#{Regexp.quote(RUBY_OPEN)}|#{Regexp.quote(RUBY_CLOSE)}|#{Regexp.quote(IMAGE_OPEN)}|#{Regexp.quote(IMAGE_CLOSE)}|#{Regexp.quote(LABEL_OPEN)}|#{Regexp.quote(LABEL_CLOSE)}|#{Regexp.quote(LABEL_HTML_OPEN)}|#{Regexp.quote(LABEL_HTML_CLOSE)}|#{Regexp.quote(REFERENCE_OPEN)}|#{Regexp.quote(REFERENCE_CLOSE)}|#{Regexp.quote(REFERENCE_HTML_OPEN)}|#{Regexp.quote(REFERENCE_HTML_CLOSE)}|#{Regexp.quote(MANUEDO_OPEN)}|#{Regexp.quote(MANUEDO_CLOSE)}|#{Regexp.quote(VERB_OPEN)}|#{Regexp.quote(VERB_CLOSE)}|#{Regexp.quote(ERB_OPEN)}|#{Regexp.quote(ERB_CLOSE)}|#{Regexp.quote(BAR)}|#{Regexp.quote(QUOTE)}|#{Regexp.quote(SLASH)}|#{Regexp.quote(BACK_SLASH)})", other_re_mode)
287
-
261
+ "\\A.+?(?=#{Regexp.quote(EM_OPEN)}|#{Regexp.quote(EM_CLOSE)}|#{Regexp.quote(ITALIC_OPEN)}|#{Regexp.quote(ITALIC_CLOSE)}|#{Regexp.quote(STRIKE_OPEN)}|#{Regexp.quote(STRIKE_CLOSE)}|#{Regexp.quote(FOOTNOTE_OPEN)}|#{Regexp.quote(FOOTNOTE_CLOSE)}|#{Regexp.quote(RUBY_OPEN)}|#{Regexp.quote(RUBY_CLOSE)}|#{Regexp.quote(IMAGE_OPEN)}|#{Regexp.quote(IMAGE_CLOSE)}|#{Regexp.quote(LABEL_OPEN)}|#{Regexp.quote(LABEL_CLOSE)}|#{Regexp.quote(LABEL_HTML_OPEN)}|#{Regexp.quote(LABEL_HTML_CLOSE)}|#{Regexp.quote(REFERENCE_OPEN)}|#{Regexp.quote(REFERENCE_CLOSE)}|#{Regexp.quote(REFERENCE_HTML_OPEN)}|#{Regexp.quote(REFERENCE_HTML_CLOSE)}|#{Regexp.quote(MANUEDO_OPEN)}|#{Regexp.quote(MANUEDO_CLOSE)}|#{Regexp.quote(VERB_OPEN)}|#{Regexp.quote(VERB_CLOSE)}|#{Regexp.quote(ERB_OPEN)}|#{Regexp.quote(ERB_CLOSE)}|#{Regexp.quote(HERB_OPEN)})", other_re_mode)
288
262
 
289
263
  def parse(src)
290
264
  @src = StringScanner.new(Array(src).join)
@@ -404,22 +378,10 @@ def next_token
404
378
  puts "i: ERB_CLOSE: #{ret}" if @view_token_type
405
379
  @pre << ret
406
380
  [:ERB_CLOSE, ret]
407
- elsif ret = @src.scan(BAR_RE)
408
- puts "i: BAR: #{ret}" if @view_token_type
409
- @pre << ret
410
- [:BAR, ret]
411
- elsif ret = @src.scan(QUOTE_RE)
412
- puts "i: QUOTE: #{ret}" if @view_token_type
413
- @pre << ret
414
- [:QUOTE, ret]
415
- elsif ret = @src.scan(SLASH_RE)
416
- puts "i: SLASH: #{ret}" if @view_token_type
417
- @pre << ret
418
- [:SLASH, ret]
419
- elsif ret = @src.scan(BACK_SLASH_RE)
420
- puts "i: BACK_SLASH: #{ret}" if @view_token_type
381
+ elsif ret = @src.scan(HERB_OPEN_RE)
382
+ puts "i: HERB_OPEN: #{ret}" if @view_token_type
421
383
  @pre << ret
422
- [:BACK_SLASH, ret]
384
+ [:HERB_OPEN, ret]
423
385
  elsif ret = @src.scan(OTHER_RE)
424
386
  puts "i: OTHER_RE: #{ret}" if @view_token_type
425
387
  @pre << ret