leandocument 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -0
- data/leandocument.gemspec +1 -0
- data/lib/leandocument.rb +2 -0
- data/lib/leandocument/document.rb +35 -15
- data/lib/leandocument/render/markdown.rb +1 -0
- data/lib/leandocument/render/re_structured_text.rb +28 -0
- data/lib/leandocument/version.rb +1 -1
- metadata +19 -2
data/README.md
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
> gem install leandocument
|
6
6
|
|
7
|
+
- Install Python and docutils if you use reStructuredText.
|
8
|
+
|
7
9
|
## Usage
|
8
10
|
|
9
11
|
> $ cd **LEANDOCUMENT_DIR**
|
@@ -21,6 +23,14 @@ and
|
|
21
23
|
|
22
24
|
## ChangeLog
|
23
25
|
|
26
|
+
### 0.1.2
|
27
|
+
|
28
|
+
- Support reStructuredText.
|
29
|
+
|
30
|
+
### 0.1.1
|
31
|
+
|
32
|
+
- Move to Document.content method to public.
|
33
|
+
|
24
34
|
### 0.1.0
|
25
35
|
|
26
36
|
- Dummy gem version update.
|
data/leandocument.gemspec
CHANGED
data/lib/leandocument.rb
CHANGED
@@ -9,7 +9,9 @@ require "leandocument/blob_image"
|
|
9
9
|
require "leandocument/repository"
|
10
10
|
require "leandocument/render"
|
11
11
|
require "leandocument/render/markdown"
|
12
|
+
require "leandocument/render/re_structured_text"
|
12
13
|
require "rdiscount"
|
14
|
+
require 'rbst'
|
13
15
|
require "yaml"
|
14
16
|
require 'grit'
|
15
17
|
require 'digest/md5'
|
@@ -7,7 +7,7 @@
|
|
7
7
|
module Leandocument
|
8
8
|
class Document
|
9
9
|
SETTING_FILE_NAME = "settings.yml"
|
10
|
-
SUPPORT_EXTENSIONS = %w(md textile markdown mdown rdoc org creole mediawiki)
|
10
|
+
SUPPORT_EXTENSIONS = %w(md textile markdown mdown rdoc org creole mediawiki rst rest)
|
11
11
|
|
12
12
|
# lang :: Document language. TODO support default language.
|
13
13
|
# settings :: LeanDocument Settings. TODO read settings.
|
@@ -49,6 +49,7 @@ module Leandocument
|
|
49
49
|
# ==== Return
|
50
50
|
# HTML content.
|
51
51
|
def to_html
|
52
|
+
return "" unless file_name
|
52
53
|
return e if e?
|
53
54
|
page = render.to_html
|
54
55
|
path = File.dirname(file_path)
|
@@ -90,10 +91,24 @@ module Leandocument
|
|
90
91
|
@toc += toc
|
91
92
|
end
|
92
93
|
|
94
|
+
# Return file content or blank string
|
95
|
+
# ==== Return
|
96
|
+
# File content. Or blank string if file not found.
|
97
|
+
def content
|
98
|
+
return @content if @content
|
99
|
+
if self.commit
|
100
|
+
@content = find_content ? find_content.data.force_encoding('UTF-8') : ""
|
101
|
+
else
|
102
|
+
@content = File.exist?(self.file_path) ? open(self.file_path).read.force_encoding('UTF-8') : ""
|
103
|
+
end
|
104
|
+
@content
|
105
|
+
end
|
106
|
+
|
93
107
|
protected
|
94
108
|
|
95
109
|
def get_extension
|
96
110
|
SUPPORT_EXTENSIONS.each do |ext|
|
111
|
+
next unless file_path(ext)
|
97
112
|
return ext if File.exist?(file_path(ext))
|
98
113
|
end
|
99
114
|
return nil
|
@@ -121,13 +136,23 @@ module Leandocument
|
|
121
136
|
end
|
122
137
|
|
123
138
|
def basic_file_name(ext = nil)
|
124
|
-
"README.#{self.lang}.#{ext ? ext : self.extension}"
|
139
|
+
f = "README.#{self.lang}.#{ext ? ext : self.extension}"
|
140
|
+
return f if File.exist? f
|
141
|
+
ary = Dir.entries(self.base_path).collect do |f|
|
142
|
+
if f =~ /^README\.([a-z]{2})\.(#{SUPPORT_EXTENSIONS.join("|")})/
|
143
|
+
self.lang = $1
|
144
|
+
self.extension = $2
|
145
|
+
return f
|
146
|
+
end
|
147
|
+
end
|
148
|
+
nil
|
125
149
|
end
|
126
150
|
|
127
151
|
# Return file path
|
128
152
|
# ==== Return
|
129
153
|
# Document file path
|
130
154
|
def file_path(ext = nil)
|
155
|
+
return nil unless file_name(ext)
|
131
156
|
"#{self.base_path}/#{file_name(ext)}"
|
132
157
|
end
|
133
158
|
|
@@ -143,19 +168,6 @@ module Leandocument
|
|
143
168
|
end
|
144
169
|
end
|
145
170
|
|
146
|
-
# Return file content or blank string
|
147
|
-
# ==== Return
|
148
|
-
# File content. Or blank string if file not found.
|
149
|
-
def content
|
150
|
-
return @content if @content
|
151
|
-
if self.commit
|
152
|
-
@content = find_content ? find_content.data.force_encoding('UTF-8') : ""
|
153
|
-
else
|
154
|
-
@content = File.exist?(self.file_path) ? open(self.file_path).read.force_encoding('UTF-8') : ""
|
155
|
-
end
|
156
|
-
@content
|
157
|
-
end
|
158
|
-
|
159
171
|
def render
|
160
172
|
return nil unless self.extension
|
161
173
|
send("render_#{self.extension}")
|
@@ -171,6 +183,14 @@ module Leandocument
|
|
171
183
|
end
|
172
184
|
alias :render_md :render_markdown
|
173
185
|
|
186
|
+
def render_rst
|
187
|
+
return @render if @render
|
188
|
+
@render = ReStructuredText.new(:content => content, :indent => self.indent, :path => self.commit ? "/commits/#{self.commit.id}#{self.web_path}" : self.web_path)
|
189
|
+
@render
|
190
|
+
end
|
191
|
+
alias :render_re_structured_text :render_rst
|
192
|
+
alias :render_rest :render_rst
|
193
|
+
|
174
194
|
def setting_value(*ary)
|
175
195
|
return nil unless self.settings
|
176
196
|
results = self.settings
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Leandocument
|
2
|
+
class ReStructuredText < Render
|
3
|
+
def to_html
|
4
|
+
html = RbST.new(exec_trans).to_html
|
5
|
+
6.times do |i|
|
6
|
+
html = html.gsub("<h#{6 - i}", "<h#{5 - i + indent}").gsub("</h#{6 - i}>", "</h#{5 - i + indent}>")
|
7
|
+
end
|
8
|
+
html
|
9
|
+
end
|
10
|
+
|
11
|
+
# Convert to something from content.
|
12
|
+
# Currently, Change indent level.
|
13
|
+
# TODO support plugin and expand format.
|
14
|
+
# ==== Return
|
15
|
+
# Text content.
|
16
|
+
def exec_trans
|
17
|
+
content = indented_content
|
18
|
+
content = content.gsub(/^\.\. image:: (.*)$/, '.. image:: '+self.path+'\\1') # For image
|
19
|
+
end
|
20
|
+
|
21
|
+
def indented_content
|
22
|
+
content = analyse_content
|
23
|
+
unless self.indent == 1
|
24
|
+
content = "#{"="*30}\n#{title}\n#{"="*30}\n\n#{content}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/leandocument/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leandocument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2012-11-
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: slop
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: RbST
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
description: Ruby command and Web viewer for LeanDocument.
|
95
111
|
email:
|
96
112
|
- atsushi@moongift.jp
|
@@ -111,6 +127,7 @@ files:
|
|
111
127
|
- lib/leandocument/document.rb
|
112
128
|
- lib/leandocument/render.rb
|
113
129
|
- lib/leandocument/render/markdown.rb
|
130
|
+
- lib/leandocument/render/re_structured_text.rb
|
114
131
|
- lib/leandocument/repository.rb
|
115
132
|
- lib/leandocument/server.rb
|
116
133
|
- lib/leandocument/version.rb
|