raf 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ef425f171fb1428d84f05600664075ccd486eb9
4
+ data.tar.gz: 3a34f1507f9d623723aff59b15ce1e5998ef4b8e
5
+ SHA512:
6
+ metadata.gz: cc6503f3a492c31334c8e3a9cf7f75b0fc8c21fdd6b71349e948fba1ad5b71aa23efcd69f0c1a2cf7b58dd798ef5134e37583a3f429d6f77adee2462f1f36c43
7
+ data.tar.gz: 49c818d4053e7f257afb84e774b9cbebe22eba46b52c05e7f76dd5f8641d6e2a0fe3aff7040f349f3787175c682c3ee38c9ee3fe9e76a6c0e263aa8c369a6b60
data/.gitignore ADDED
@@ -0,0 +1,42 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ #*.swp
data/Gemfile CHANGED
@@ -1,13 +1,4 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'https://rubygems.org'
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
13
- end
3
+ # Specify your gem's dependencies in raf.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,20 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ raf (0.2.0)
5
+
1
6
  GEM
2
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
3
8
  specs:
4
- git (1.2.5)
5
- jeweler (1.5.2)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- rake (0.8.7)
10
- rcov (0.9.9)
11
- shoulda (2.11.3)
9
+ rake (10.1.0)
12
10
 
13
11
  PLATFORMS
14
12
  ruby
15
13
 
16
14
  DEPENDENCIES
17
- bundler (~> 1.0.0)
18
- jeweler (~> 1.5.2)
19
- rcov
20
- shoulda
15
+ bundler (~> 1.3)
16
+ raf!
17
+ rake
data/History.rdoc CHANGED
@@ -1,3 +1,15 @@
1
+ == 0.1.0 2013-11-26
2
+ * Ruby-2.0.0 をサポート
3
+ * Ruby-1.8.x, Ruby-1.9.x のサポートを終了
4
+ * ERB書式(<%=...%>)を正しく処理できていなかった問題を修正
5
+
6
+ == 0.0.5 2012-12-12
7
+ * supported ruby1.8 only
8
+
9
+ == 0.0.4 2012-12-10
10
+ * added "-*- encoding: utf-8 -*-" in code files.
11
+ * support ruby1.9
12
+
1
13
  == 0.0.3 2011-04-10
2
14
  * typo fix
3
15
 
data/README.rdoc CHANGED
@@ -1,8 +1,15 @@
1
1
  = raf
2
2
  "raf" is simple document format.
3
- refer to : http://garin.jp/doc/Software/raf (this page is japanese)
3
+ refer to : http://garin.jp/doc/raf/raf (this page is japanese)
4
+
5
+ == install
6
+ // check ruby version
7
+ $ ruby -v
8
+ ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
9
+
10
+ // raf gem package install
11
+ $ gem install raf
4
12
 
5
13
  == Copyright
6
- Copyright (c) 2011 garin. See LICENSE.txt for
14
+ Copyright (c) 2011-2013 garin. See LICENSE.txt for
7
15
  further details.
8
-
data/Rakefile CHANGED
@@ -1,53 +1 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "raf"
16
- gem.homepage = "http://github.com/garin/raf"
17
- gem.license = "GPL"
18
- gem.summary = %Q{raf is simple document format}
19
- gem.description = %Q{raf is simple document format}
20
- gem.email = "garin54@gmail.com"
21
- gem.authors = ["garin"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
-
36
- require 'rcov/rcovtask'
37
- Rcov::RcovTask.new do |test|
38
- test.libs << 'test'
39
- test.pattern = 'test/**/test_*.rb'
40
- test.verbose = true
41
- end
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "raf #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
1
+ require "bundler/gem_tasks"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.1.0
data/bin/raf2html CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # Copyright (C) garin <garin54@gmail.com> 2011
4
+ # See the included file COPYING for details.
2
5
  $:.unshift File.join(File.dirname(__FILE__), "../lib")
3
6
  require "optparse"
4
- require "rafblockparser.tab"
5
7
  require "raf2html"
6
8
 
7
9
  options = {:css => nil, :language => 'ja', :index => true, :quiet => false}
@@ -11,6 +13,7 @@ opt = OptionParser.new do |opt|
11
13
  opt.on("--css file", "スタイルシートのファイルを指定") {|f| options[:css] = f}
12
14
  opt.on("-L", "--language LANG", "言語(デフォルトは #{options[:language]} 。ドキュメント側で指定されていればそちらを優先)"){|l| options[:language] = l}
13
15
  opt.on("--[no-]index", "目次を生成する(デフォルトは生成する)"){|v| options[:index] = v }
16
+ opt.on("--[no-]metadata", "メタ情報を出力しない(デフォルトは出力する)"){|v| options[:metadata] = v }
14
17
  opt.on("-q","--quiet", "本文だけを出力する(ヘッダやフッタは出力しない)"){ options[:quiet] = true }
15
18
  end
16
19
  opt.parse!(ARGV)
data/lib/parserutility.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Copyright (C) garin <garin54@gmail.com> 2011
2
+ # See the included file COPYING for details.
3
+ # -*- encoding: utf-8 -*-
1
4
  module ParserUtility
2
5
  def add_children_to_element(obj, *val)
3
6
  obj.add = *val
data/lib/raf2html.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) garin <garin54@gmail.com> 2011
3
+ # See the included file COPYING for details.
1
4
  require "raf2html_element"
2
5
  require "cgi"
3
6
 
@@ -10,24 +13,25 @@ module Raf
10
13
  @css = File.open(options[:css]).readlines.to_s unless options[:css].nil?
11
14
  @language = options[:language]
12
15
  @index = options[:index]
16
+ @metadata = options[:metadata]
13
17
  @quiet = options[:quiet]
14
18
 
15
19
  @raf = BlockParser.new
16
- @info = setup_info
20
+ @metadata = setup_metadata
17
21
  @nodes = @raf.parse src.map {|s| CGI.escapeHTML(s) }
18
22
  end
19
23
 
20
- def setup_info
21
- info = @raf.info
22
- info[:language] = @language if info[:language].nil?
23
- info
24
+ def setup_metadata
25
+ metadata = @raf.metadata
26
+ metadata[:language] = @language if metadata[:language].nil?
27
+ metadata
24
28
  end
25
29
 
26
30
  def to_html
27
31
  html = ""
28
32
  html += header unless @quiet
29
33
  html += header_title
30
- html += metadata
34
+ html += metadata if @metadata
31
35
  html += index if @index
32
36
  html += body
33
37
  html += footnote
@@ -36,7 +40,7 @@ module Raf
36
40
  end
37
41
 
38
42
  def body
39
- @nodes.map do |node| node.apply end.to_s
43
+ @nodes.map do |node| node.apply end.join
40
44
  end
41
45
 
42
46
 
@@ -48,11 +52,10 @@ module Raf
48
52
  next if h[:level] == 1 or h[:level] == 6
49
53
 
50
54
  if h[:level] == 5
51
- str += '<br />'
52
- str += "<a href='#raf-head#{h[:level]}-#{i+1}' style='padding-left: 1em'>#{h[:title]}</a>\n"
55
+ str += "<div class=><a href='#raf-head#{h[:level]}-#{i+1}'><span class='space' />#{h[:title]}</a></div>\n"
53
56
  else
54
57
  str += index_terminate(h[:level], level_pre)
55
- str += "<li><a href='#raf-head#{h[:level]}-#{i+1}'>#{h[:index]} #{h[:title]}</a>\n"
58
+ str += "<li><a href='#raf-head#{h[:level]}-#{i+1}'>#{h[:index]}#{h[:title]}</a>\n"
56
59
  level_pre = h[:level]
57
60
  end
58
61
  end
@@ -82,30 +85,15 @@ module Raf
82
85
  str = "<div id='raf-metadata'>"
83
86
  str += "<table id='raf-metadata-table'>"
84
87
  str_pre = ""
85
- str_pre += "<tr><th>著者</th><td colspan='3'>#{@info[:creator]}</td></tr>" unless @info[:creator].nil?
86
-
87
- unless @info[:date].nil? or @info[:update].nil?
88
- str_pre += "<tr>"
89
- str_pre += "<th>作成日</th><td>#{@info[:date]}</td>" unless @info[:date].nil?
90
- str_pre += "<th>更新日</th><td>#{@info[:update]}</td>" unless @info[:update].nil?
91
- str_pre += "</tr>"
92
- end
93
-
94
- unless @info[:publisher].nil? or @info[:version].nil?
95
- str_pre += "<tr>"
96
- str_pre += "<th>発行</th><td>#{@info[:publisher]}</td>" unless @info[:publisher].nil?
97
- str_pre += "<th>バージョン</th><td>#{@info[:version]}</td>" unless @info[:version].nil?
98
- str_pre += "</tr>"
99
- end
100
-
101
- unless @info[:contributor].nil? or @info[:revison].nil?
102
- str_pre += "<tr>"
103
- str_pre += "<th>寄稿者</th>#{@info[:contributor]}</td>" unless @info[:contributor].nil?
104
- str_pre += "<th>リビジョン</th><td>#{@info[:revison]}</td>" unless @info[:revison].nil?
105
- str_pre += "</tr>"
106
- end
107
-
108
- str_pre += "<tr><th>概要</th><td colspan='4'>#{@info[:description]}</td></tr>" unless @info[:description].nil?
88
+ str_pre += "<tr><th>著者</th><td colspan='3'>#{@metadata[:creator]}</td></tr>" unless @metadata[:creator].nil?
89
+ str_pre += "<tr><th>公開日</th><td>#{@metadata[:date]}</td></tr>" unless @metadata[:date].nil?
90
+ str_pre += "<tr><th>更新日</th><td>#{@metadata[:update]}</td></tr>" unless @metadata[:update].nil?
91
+ str_pre += "<tr><th>タグ</th><td>#{@metadata[:tag]}</td></tr>" unless @metadata[:tag].nil?
92
+ str_pre += "<tr><th>発行</th><td>#{@metadata[:publisher]}</td></tr>" unless @metadata[:publisher].nil?
93
+ str_pre += "<tr><th>バージョン</th><td>#{@metadata[:version]}</td></tr>" unless @metadata[:version].nil?
94
+ str_pre += "<tr><th>寄稿者</th>#{@metadata[:contributor]}</tr></td>" unless @metadata[:contributor].nil?
95
+ str_pre += "<tr.<th>リビジョン</th><td>#{@metadata[:revison]}</tr></td>" unless @metadata[:revison].nil?
96
+ str_pre += "<tr><th>概要</th><td colspan='4'>#{@metadata[:description]}</td></tr>" unless @metadata[:description].nil?
109
97
 
110
98
  if str_pre.empty?
111
99
  str_pre
@@ -118,8 +106,8 @@ module Raf
118
106
  return "" if @raf.inline_index[:footnote].nil?
119
107
  str = "<div id='raf-footnote'>"
120
108
  @raf.inline_index[:footnote].each_with_index do |f,i|
121
- str += "<a id='raf-footnote-#{i+1}' />"
122
- str += "<a href='#raf-footnote-#{i+1}-reverse'>*#{i+1}</a>"
109
+ str += "<a id='raf-footnote-#{i+1}' class='footnote' />"
110
+ str += "<a href='#raf-footnote-#{i+1}-reverse' class='footnote-reverse'>*#{i+1}</a>"
123
111
  str += " #{f[:content].map{|c| c.apply}}<br />"
124
112
  end
125
113
  str += "</div>"
@@ -130,20 +118,20 @@ module Raf
130
118
  str = <<EOL
131
119
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
132
120
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
133
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="#{@info[:language]}">
121
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="#{@metadata[:language]}">
134
122
  <head>
135
123
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
136
124
  EOL
137
125
  str += css
138
126
  str += <<EOL
139
- <title>#{@info[:subject]}</title>
127
+ <title>#{@metadata[:subject]}</title>
140
128
  </head>
141
129
  <body>
142
130
  EOL
143
131
  end
144
132
 
145
133
  def header_title
146
- "<h1>#{@info[:subject]}</h1>\n"
134
+ "<h1>#{@metadata[:subject]}</h1>\n"
147
135
  end
148
136
 
149
137
  def css
@@ -158,10 +146,9 @@ EOL
158
146
 
159
147
  def footer
160
148
  str = "\n"
161
- str += "<div id='rights'>#{@info[:rights]}</div>\n" unless @info[:rights].nil?
149
+ str += "<div id='rights'>#{@metadata[:rights]}</div>\n" unless @metadata[:rights].nil?
162
150
  str += "</body>\n</html>"
163
151
  str
164
152
  end
165
153
  end
166
154
  end
167
-
@@ -1,5 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) garin <garin54@gmail.com> 2011
3
+ # See the included file COPYING for details.
4
+ require "rafblockparser.tab"
1
5
  module Raf
2
-
6
+
3
7
  class Element
4
8
  def newline_to_br(str)
5
9
  str.gsub("\n", "<br />\n")
@@ -14,33 +18,33 @@ module Raf
14
18
  str
15
19
  end
16
20
  end
17
-
21
+
18
22
  # ----- Blocks
19
23
  class WhiteLine < Element
20
24
  def apply
21
25
  "\n"
22
26
  end
23
27
  end
24
-
28
+
25
29
  class PlainTextBlock < Element
26
30
  def apply
27
31
  @contents.map {|c| c.apply }
28
32
  end
29
33
  end
30
-
34
+
31
35
  class HeadLine < Element
32
36
  # @contents = [level, title, id, index]
33
37
  def apply
34
38
  return "" if @contents[0] == 1
35
39
  str = ""
36
- str += "<h#{@contents[0]} id='raf-head#{@contents[0]}-#{@contents[2]}' class='raf-headline'>"
40
+ str += "<h#{@contents[0]} id='raf-head#{@contents[0]}-#{@contents[2]}'>"
37
41
  str += "<a id='#{@contents[1].to_code}'></a>"
38
- str += "#{@contents[3]}" unless @contents[0] == 1 or @contents[0] == 5 or @contents[0] == 6
42
+ str += " #{@contents[3]}" unless @contents[0] == 1 or @contents[0] == 5 or @contents[0] == 6
39
43
  str += "#{@contents[1]}</h#{@contents[0]}>\n"
40
44
  str
41
45
  end
42
46
  end
43
-
47
+
44
48
  class Paragraph < Element
45
49
  def apply
46
50
  "<p>#{@contents.map{|c| c.apply}}</p>\n"
@@ -51,7 +55,7 @@ module Raf
51
55
  def apply
52
56
  "<pre>#{@contents}</pre>\n"
53
57
  end
54
- end
58
+ end
55
59
 
56
60
  class ItemList < Element
57
61
  def apply
@@ -62,14 +66,14 @@ module Raf
62
66
  type_pre = type
63
67
  case item
64
68
  when :INDENT
65
- type = :indent
69
+ type = :indent
66
70
  str += "\n<ul>\n"
67
71
  when :DEDENT
68
- type = :dedent
69
- str += "</li>\n" if type_pre == :item
72
+ type = :dedent
73
+ str += "</li>\n" if type_pre == :item
70
74
  str += "</ul>\n</li>\n"
71
75
  else
72
- type = :item
76
+ type = :item
73
77
  str += "</li>\n" if type_pre == :item
74
78
  str += "<li>#{item.apply}"
75
79
  end
@@ -93,7 +97,7 @@ module Raf
93
97
  end
94
98
  end
95
99
  str += "</ol>\n"
96
- str
100
+ str
97
101
  end
98
102
  end
99
103
 
@@ -116,7 +120,7 @@ module Raf
116
120
  if item =~ /^\s*\*/
117
121
  str += "<th>#{item.sub(/^\s*\*/, "").sub(/\*\s*$/,"")}</th>"
118
122
  else
119
- str += "<td>#{item}</td>"
123
+ str += "<td>#{item}</td>"
120
124
  end
121
125
  end
122
126
  str += "\n</tr>"
@@ -126,28 +130,27 @@ module Raf
126
130
  end
127
131
  end
128
132
  # --- Blocks end
129
-
130
- # --- Inlines
133
+
134
+ # --- Inlines
131
135
  class Label < Element
132
136
  # @contents = [label, title]
133
137
  def apply
134
138
  "<a href='##{@contents[0]}' id='#{@contents[0]}'>#{@contents[1]}</a>"
135
139
  end
136
140
  end
137
-
141
+
138
142
  class Reference < Element
139
143
  def apply
140
144
  "<a href='#{@contents[1]}' title='#{@contents[1]}'>#{@contents[0]}</a>"
141
145
  end
142
146
  end
143
147
 
144
-
145
148
  class Plain < Element
146
149
  def apply
147
150
  "#{newline_to_br(@contents.join(""))}"
148
151
  end
149
152
  end
150
-
153
+
151
154
  class Emphasis < Element
152
155
  def apply
153
156
  "<em>#{@contents.map{|c| c.apply}}</em>"
@@ -180,16 +183,16 @@ module Raf
180
183
  "<ruby><rb>#{@contents[0]}</rb><rp>(</rp><rt>#{@contents[1]}</rt><rp>)</rp></ruby>"
181
184
  end
182
185
  end
183
-
186
+
184
187
  class Footnote < Element
185
188
  def apply
186
- "<a href='#raf-footnote-#{@contents[1]}' name='raf-footnote-#{@contents[1]}-reverse' title='#{@contents[0].map {|c| c.apply}}'><sup><small>*#{@contents[1]}</small></sup></a>"
189
+ "<a href='#raf-footnote-#{@contents[1]}' name='raf-footnote-#{@contents[1]}-reverse' title='#{@contents[0].map {|c| c.apply}}' class='footnote-reverse'><sup><small>*#{@contents[1]}</small></sup></a>"
187
190
  end
188
- end
191
+ end
189
192
 
190
193
  class Image < Element
191
194
  def apply
192
195
  "<img src='#{@contents}' />"
193
196
  end
194
- end
197
+ end
195
198
  end
@@ -1,3 +1,5 @@
1
+ # Copyright (C) garin <garin54@gmail.com> 2011
2
+ # See the included file COPYING for details.
1
3
  class BlockParser
2
4
  token HEADER WHITELINE HEADLINE PLAIN DESCLINE_TITLE DESCLINE QUOTE INDENT DEDENT ITEMLIST ITEMLISTCONTINUE NUMLIST TABLELINE
3
5
  preclow
@@ -26,7 +28,7 @@ class BlockParser
26
28
  name, val = val[0].split(":",2)
27
29
  if name.nil? or val.nil?
28
30
  else
29
- @info.update({name.strip.to_sym => val.strip })
31
+ @metadata.update({name.strip.to_sym => val.strip })
30
32
  end
31
33
  nil }
32
34
 
@@ -35,7 +37,7 @@ class BlockParser
35
37
  title = val[0][1]
36
38
  level = val[0][0]
37
39
  if level == 1
38
- @info[:subject] ||= title
40
+ @metadata[:subject] ||= title
39
41
  else
40
42
  @head_index.update(level)
41
43
  end
@@ -138,16 +140,16 @@ end
138
140
 
139
141
  def initialize
140
142
  @inline_parser = InlineParser.new
141
- @info = {}
143
+ @metadata = {}
142
144
  @inline_index = @inline_parser.index
143
145
  @index = {}
144
146
  @head_index = HeadIndex.new
145
147
  end
146
- attr_reader :info, :inline_index, :index
148
+ attr_reader :metadata, :inline_index, :index
147
149
 
148
150
  def parse(src)
149
151
  @no = 0
150
- @src = src.to_a
152
+ @src = Array(src)
151
153
  @line = Line.new("")
152
154
  @line_pre = @line.dup
153
155
  @indent_stack = []