tartancloth 0.0.1 → 0.0.2
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/.rspec +2 -0
- data/CHANGELOG.txt +9 -0
- data/README.md +237 -200
- data/lib/tartancloth.rb +417 -335
- data/spec/lib/matchers.rb +110 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/toc_spec.rb +37 -0
- metadata +11 -3
data/.rspec
ADDED
data/CHANGELOG.txt
ADDED
data/README.md
CHANGED
@@ -1,200 +1,237 @@
|
|
1
|
-
# TartanCloth
|
2
|
-
|
3
|
-
A wrapper around the BlueCloth gem which incorporates HTML5 headers, footers,
|
4
|
-
and a table of contents all with a nice stylesheet.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
My Wrench
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
1
|
+
# TartanCloth
|
2
|
+
|
3
|
+
A wrapper around the BlueCloth gem which incorporates HTML5 headers, footers,
|
4
|
+
and a table of contents all with a nice stylesheet.
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'tartancloth'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tartancloth
|
20
|
+
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TartanCloth's main feature is generating a _linked_ Table of Contents
|
25
|
+
from the headers (`h1, h2, h3, h4, h5, h6`) in your markdown document.
|
26
|
+
|
27
|
+
Simply add a header at any header level (level 2: `h2`, shown here):
|
28
|
+
|
29
|
+
## TOC
|
30
|
+
|
31
|
+
TartanCloth will parse the document and collect all headers **after** the TOC
|
32
|
+
and create a Table of Contents. The Table of Contents will be inserted at the
|
33
|
+
location of the `## TOC` header, replacing it.
|
34
|
+
|
35
|
+
In most of my documents, I include the Title (h1) and a summary before
|
36
|
+
displaying the TOC. I didn't want to include the sections prior to the TOC in
|
37
|
+
the Table of Contents, that's why header collection starts after.
|
38
|
+
|
39
|
+
|
40
|
+
### Quick Example
|
41
|
+
|
42
|
+
A quick example of using TartanCloth.
|
43
|
+
|
44
|
+
Given the following markdown:
|
45
|
+
|
46
|
+
|
47
|
+
###### markdown.md
|
48
|
+
|
49
|
+
# My Wrench User Manual
|
50
|
+
|
51
|
+
## Summary
|
52
|
+
|
53
|
+
My Wrench is an awesome tool blah, blah blah.
|
54
|
+
|
55
|
+
- - -
|
56
|
+
## TOC
|
57
|
+
|
58
|
+
- - -
|
59
|
+
## Running Wrench from the command line
|
60
|
+
|
61
|
+
How to run wrench from the command line
|
62
|
+
|
63
|
+
- - -
|
64
|
+
## Documentation Conventions
|
65
|
+
|
66
|
+
Text surrounded with square brackets [] is optional.
|
67
|
+
Text formatted like `this` indicates a _keyword_.
|
68
|
+
|
69
|
+
### Some Other Header
|
70
|
+
|
71
|
+
#### Another, Deeper Header
|
72
|
+
|
73
|
+
##### Yet Another Header
|
74
|
+
|
75
|
+
- - -
|
76
|
+
## Look at this header
|
77
|
+
|
78
|
+
###### Small Note Header
|
79
|
+
|
80
|
+
|
81
|
+
Markit.rb will convert the markdown to HTML, with an embedded stylesheet and
|
82
|
+
include a Table of Contents.
|
83
|
+
|
84
|
+
###### markit.rb
|
85
|
+
|
86
|
+
require 'tartancloth'
|
87
|
+
|
88
|
+
title = 'My Markdown'
|
89
|
+
mdsrc = 'path/to/my/markdown.md'
|
90
|
+
mdout = 'path/to/my/markdown.html'
|
91
|
+
|
92
|
+
puts "Title: #{title}"
|
93
|
+
puts "Source: #{mdsrc}"
|
94
|
+
puts "Output: #{mdout}"
|
95
|
+
|
96
|
+
TartanCloth.new( mdsrc, title ).to_html_file( mdout )
|
97
|
+
|
98
|
+
|
99
|
+
### Using TartanCloth from a Rake Task
|
100
|
+
|
101
|
+
I like to use TartanCloth from a rake task to generate pretty docs.
|
102
|
+
|
103
|
+
###### markdown.rake
|
104
|
+
|
105
|
+
require "pathname"
|
106
|
+
require 'tartancloth'
|
107
|
+
|
108
|
+
# Call this as: rake md2html[path/to/file/to/convert.md]
|
109
|
+
#
|
110
|
+
desc "Convert a .MD file to HTML"
|
111
|
+
task :md2html, [:mdfile] do |t, args|
|
112
|
+
Rake::Task['markdown:md2html'].invoke( args[:mdfile] )
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
namespace :markdown do
|
117
|
+
|
118
|
+
desc "md2html usage instructions"
|
119
|
+
task :help do
|
120
|
+
puts <<HELP
|
121
|
+
|
122
|
+
----------------------------------------------------------------------
|
123
|
+
|
124
|
+
Usage: md2html
|
125
|
+
|
126
|
+
Generate HTML from a markdown document
|
127
|
+
|
128
|
+
The generated HTML document will be located in the same location as
|
129
|
+
the source markdown document.
|
130
|
+
|
131
|
+
To generate the document, call it as follows:
|
132
|
+
|
133
|
+
rake md2html[path/to/doc.md]
|
134
|
+
|
135
|
+
Note that no quotes are needed.
|
136
|
+
|
137
|
+
To set the title of the document, provide it as an ENV variable:
|
138
|
+
|
139
|
+
TITLE="My Title" rake md2html[path/to/doc.md]
|
140
|
+
|
141
|
+
If no title is given, the title will default to the filename.
|
142
|
+
|
143
|
+
----------------------------------------------------------------------
|
144
|
+
|
145
|
+
HELP
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
task :md2html, [:mdfile] do |t, args|
|
150
|
+
args.with_defaults(:mdfile => nil)
|
151
|
+
if args[:mdfile].nil?
|
152
|
+
puts "ERROR: Full path to file to convert required."
|
153
|
+
puts
|
154
|
+
puts "usage: rake md2html['path/to/md/file.md']"
|
155
|
+
exit
|
156
|
+
end
|
157
|
+
|
158
|
+
mdsrc = args[:mdfile]
|
159
|
+
mdout = mdsrc.pathmap( "%X.html" )
|
160
|
+
title = ENV['TITLE']
|
161
|
+
|
162
|
+
puts "Title: #{title}"
|
163
|
+
puts "Source: #{mdsrc}"
|
164
|
+
puts "Output: #{mdout}"
|
165
|
+
|
166
|
+
TartanCloth.new( mdsrc, title ).to_html_file( mdout )
|
167
|
+
end
|
168
|
+
|
169
|
+
end # namespace :markdown
|
170
|
+
|
171
|
+
|
172
|
+
### A Task to Generate a User Manual
|
173
|
+
|
174
|
+
I use the tasks above to generate a user manual as well:
|
175
|
+
|
176
|
+
|
177
|
+
###### Rakefile
|
178
|
+
|
179
|
+
require "bundler/gem_tasks"
|
180
|
+
|
181
|
+
desc 'Generate user manual HTML'
|
182
|
+
task :man do
|
183
|
+
|
184
|
+
ENV['TITLE'] = 'User Manual'
|
185
|
+
|
186
|
+
Rake::Task['markdown:md2html'].invoke( 'docs/user_manual.md' )
|
187
|
+
Rake::Task['markdown:md2html'].reenable
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
### Available Methods
|
193
|
+
|
194
|
+
The TartanCloth object provides the following methods:
|
195
|
+
|
196
|
+
###
|
197
|
+
# Convert a markdown source file to HTML. If a header element with text TOC
|
198
|
+
# exists within the markdown document, a Table of Contents will be generated
|
199
|
+
# and inserted at that location.
|
200
|
+
#
|
201
|
+
# The TOC will only contain header (h1-h6) elements from the location of the
|
202
|
+
# TOC header to the end of the document
|
203
|
+
|
204
|
+
to_html()
|
205
|
+
|
206
|
+
|
207
|
+
###
|
208
|
+
# The same as to_html() but writes the HTML to a file.
|
209
|
+
#
|
210
|
+
# html_file - path to file
|
211
|
+
|
212
|
+
to_html_file( html_file_path )
|
213
|
+
|
214
|
+
|
215
|
+
###
|
216
|
+
# Build TOC and return body content (including TOC).
|
217
|
+
# Returned HTML does NOT include doc headers, footer, or stylesheet.
|
218
|
+
#
|
219
|
+
# returns HTML that forms the body of the document
|
220
|
+
|
221
|
+
body_html()
|
222
|
+
|
223
|
+
|
224
|
+
## Credits
|
225
|
+
|
226
|
+
+ [BlueCloth](https://github.com/ged/bluecloth) is used to generate the markdown
|
227
|
+
+ [Nokogiri](http://nokogiri.org/) is used to generate the table of contents
|
228
|
+
+ Chris Coyier has some [great code for pretty HRs](http://css-tricks.com/examples/hrs/)
|
229
|
+
|
230
|
+
|
231
|
+
## Contributing
|
232
|
+
|
233
|
+
1. Fork it
|
234
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
235
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
236
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
237
|
+
5. Create new Pull Request
|