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