textile2html 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/lib/textile2html.rb +84 -22
- data/textile2html.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/textile2html.rb
CHANGED
@@ -39,34 +39,96 @@ class Textile2Html
|
|
39
39
|
RedCloth.new(src).to_html
|
40
40
|
end
|
41
41
|
|
42
|
+
EXTENSIONS = {
|
43
|
+
:textile => %w[textile],
|
44
|
+
:html_template => %w[html.erb],
|
45
|
+
:css_template => %w[css.erb],
|
46
|
+
:text => %w[html css],
|
47
|
+
:image => %w[png jpg gif icon],
|
48
|
+
}
|
49
|
+
EXTENSION_PATTERNS = EXTENSIONS.inject({}) do |dest, (t, exts)|
|
50
|
+
key = Regexp.union( exts.map{|ext| /\.#{Regexp.escape(ext)}\Z/i} )
|
51
|
+
dest[key] = t
|
52
|
+
dest
|
53
|
+
end
|
54
|
+
|
42
55
|
def execute
|
43
|
-
|
44
|
-
|
56
|
+
@layout_erb = ERB.new(File.read(options[:layout]))
|
57
|
+
@src_dir = File.expand_path(options[:src_dir])
|
58
|
+
src_files = Dir["#{@src_dir}/**/*.*"]
|
45
59
|
src_files.each do |src_file|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
when nil then html_body
|
55
|
-
when :page_outline then build_page_outlines(links)
|
56
|
-
else
|
57
|
-
nil
|
60
|
+
EXTENSION_PATTERNS.each do |pattern, ext_type|
|
61
|
+
if src_file =~ pattern
|
62
|
+
@src_path = src_file
|
63
|
+
@rel_path = src_file.sub(/^#{Regexp.escape(@src_dir)}\//, '')
|
64
|
+
@rel_path_depth = @rel_path.split(/\//).length - 1
|
65
|
+
puts "processing: #{src_file}"
|
66
|
+
send("process_#{ext_type}", src_file)
|
67
|
+
break
|
58
68
|
end
|
59
69
|
end
|
70
|
+
end
|
71
|
+
end
|
60
72
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
def process_textile(src_file)
|
74
|
+
src = ERB.new(File.read(src_file)).result
|
75
|
+
html_body = RedCloth.new(src).to_html
|
76
|
+
html_body, links = pickup_headers(html_body)
|
77
|
+
b = binding_for_yield do|*args|
|
78
|
+
arg = args.first
|
79
|
+
case arg
|
80
|
+
when nil then html_body
|
81
|
+
when :page_outline then build_page_outlines(links)
|
82
|
+
else
|
83
|
+
nil
|
84
|
+
end
|
69
85
|
end
|
86
|
+
html = @layout_erb.result(b)
|
87
|
+
write_text(src_file, html, [/\.textile$/, '.html'])
|
88
|
+
end
|
89
|
+
|
90
|
+
def process_html_template(src_file)
|
91
|
+
html_body = ERB.new(File.read(src_file)).result
|
92
|
+
b = binding_for_yield{|*args| html_body}
|
93
|
+
html = @layout_erb.result(b)
|
94
|
+
write_text(src_file, html, [/\.erb$/i, ''])
|
95
|
+
end
|
96
|
+
|
97
|
+
def process_css_template(src_file)
|
98
|
+
body = ERB.new(File.read(src_file)).result
|
99
|
+
write_text(src_file, body, [/\.erb$/i, ''])
|
100
|
+
end
|
101
|
+
|
102
|
+
def process_text(src_file)
|
103
|
+
copy(src_file)
|
104
|
+
end
|
105
|
+
|
106
|
+
def process_image(src_file)
|
107
|
+
copy(src_file)
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def copy(src_file, path_sub_args = [])
|
113
|
+
dest_path = dest_path(src_file, path_sub_args)
|
114
|
+
dest_dir = File.dirname(dest_path)
|
115
|
+
FileUtils.mkdir_p(dest_dir)
|
116
|
+
FileUtils.cp(src_file, dest_path)
|
70
117
|
end
|
71
118
|
|
119
|
+
def write_text(src_file, text, path_sub_args)
|
120
|
+
dest_path = dest_path(src_file, path_sub_args)
|
121
|
+
dest_dir = File.dirname(dest_path)
|
122
|
+
FileUtils.mkdir_p(dest_dir)
|
123
|
+
File.open(dest_path, "w"){|f| f.puts(text)}
|
124
|
+
end
|
125
|
+
|
126
|
+
def dest_path(src_file, path_sub_args)
|
127
|
+
dest_rel_path = path_sub_args.empty? ?
|
128
|
+
@rel_path :
|
129
|
+
@rel_path.sub(*path_sub_args)
|
130
|
+
File.expand_path(dest_rel_path, options[:dest_dir])
|
131
|
+
end
|
132
|
+
|
133
|
+
|
72
134
|
end
|
data/textile2html.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{textile2html}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["akimatter"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-21}
|
13
13
|
s.default_executable = %q{textile2html}
|
14
14
|
s.description = %q{textile2html generate html from textile with ERB template by using RedCloth}
|
15
15
|
s.email = %q{akm2000@gmail.com}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- akimatter
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-21 00:00:00 +09:00
|
18
18
|
default_executable: textile2html
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -139,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
139
|
requirements:
|
140
140
|
- - ">="
|
141
141
|
- !ruby/object:Gem::Version
|
142
|
-
hash:
|
142
|
+
hash: -1445524543752592999
|
143
143
|
segments:
|
144
144
|
- 0
|
145
145
|
version: "0"
|