markup 0.1.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/LICENSE +20 -0
- data/README.markdown +40 -0
- data/bin/markup +45 -0
- data/lib/markup.rb +38 -0
- data/test/markup_test.rb +76 -0
- data/test/test_helper.rb +11 -0
- metadata +90 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 James Wilding
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# markup
|
2
|
+
|
3
|
+
Markup is a small (ie tiny) command line tool for converting Markdown to HTML.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ sudo gem install markup --source http://gemcutter.org
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ markup README.markdown
|
12
|
+
Created README.html
|
13
|
+
|
14
|
+
$ cat README.html
|
15
|
+
<h1>markup</h1>
|
16
|
+
|
17
|
+
<p>Markup is a small.... etc
|
18
|
+
|
19
|
+
By default markup outputs to {sourcefile_name}.html, but you can specify a different filename using the -o option:
|
20
|
+
|
21
|
+
$ markup README.markdown -o instructions.html
|
22
|
+
|
23
|
+
Overwrite existing output using the -F option (this will clobber existing files so be careful):
|
24
|
+
|
25
|
+
$ markup README.markdown -F
|
26
|
+
|
27
|
+
## Note on Patches/Pull Requests
|
28
|
+
|
29
|
+
* Fork the project.
|
30
|
+
* Make your feature addition or bug fix.
|
31
|
+
* Add tests for it. This is important so I don't break it in a
|
32
|
+
future version unintentionally.
|
33
|
+
* Commit, do not mess with rakefile, version, or history.
|
34
|
+
(if you want to have your own version, that is fine but
|
35
|
+
bump version in a commit by itself I can ignore when I pull)
|
36
|
+
* Send me a pull request. Bonus points for topic branches.
|
37
|
+
|
38
|
+
## Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2009 James Wilding. See LICENSE for details.
|
data/bin/markup
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
# Command line tool for producing HTML from Markdown files.
|
5
|
+
# Requires rubygems and RDiscount (gem install rdiscount).
|
6
|
+
#
|
7
|
+
# Usage: markup source_file.markdown [-o output_file] [-F]
|
8
|
+
#
|
9
|
+
# For help, use markup --help
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
script = File.basename($0)
|
13
|
+
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: #{script} source_file [options]"
|
16
|
+
|
17
|
+
opts.on '-o', '--output', 'Output file [FILE]' do |file|
|
18
|
+
options[:output] = file
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on '-F', '--force', 'Overwrite output file' do |force|
|
22
|
+
options[:force] = force
|
23
|
+
end
|
24
|
+
end.parse!
|
25
|
+
|
26
|
+
unless input = ARGV.first
|
27
|
+
puts "Please specify a source file"
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rubygems'
|
33
|
+
require File.dirname(__FILE__) + '/../lib/markup'
|
34
|
+
|
35
|
+
runner = Markup::Runner.new(input, options)
|
36
|
+
output = runner.output_filename
|
37
|
+
|
38
|
+
runner.generate_html!
|
39
|
+
rescue Markup::Runner::OutputExists
|
40
|
+
puts "Output file #{output} exists: use #{script} -o to specify another"
|
41
|
+
exit 1
|
42
|
+
else
|
43
|
+
puts "Created #{output}"
|
44
|
+
exit 0
|
45
|
+
end
|
data/lib/markup.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rdiscount'
|
2
|
+
|
3
|
+
module Markup
|
4
|
+
class Runner
|
5
|
+
|
6
|
+
class OutputExists < StandardError; end
|
7
|
+
|
8
|
+
def initialize(source, options = {})
|
9
|
+
@source = source
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_html!
|
14
|
+
if output_file_exists? && should_not_overwrite_output_file?
|
15
|
+
raise OutputExists, output_filename
|
16
|
+
else
|
17
|
+
File.open(output_filename, 'w') { |f| f.write(html_output) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def output_filename
|
22
|
+
@options[:output] || File.basename(@source, '.*') + '.html'
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def html_output
|
27
|
+
RDiscount.new(File.read(@source)).to_html
|
28
|
+
end
|
29
|
+
|
30
|
+
def output_file_exists?
|
31
|
+
File.file?(output_filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
def should_not_overwrite_output_file?
|
35
|
+
!@options[:force]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/markup_test.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class MarkupTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include FileUtils
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@source = File.dirname(__FILE__) + '/../README.markdown'
|
10
|
+
@output = File.dirname(__FILE__) + '/output.html'
|
11
|
+
clear_output_file!
|
12
|
+
end
|
13
|
+
|
14
|
+
context '#output_filename' do
|
15
|
+
context 'with no options' do
|
16
|
+
should 'set output filename to input filename + "html"' do
|
17
|
+
runner = Markup::Runner.new(@source)
|
18
|
+
expected = 'README.html'
|
19
|
+
actual = runner.output_filename
|
20
|
+
|
21
|
+
assert_equal expected, actual
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with options[:output] set' do
|
26
|
+
should 'use options[:output] as output filename' do
|
27
|
+
runner = Markup::Runner.new(@source, :output => 'instructions.html')
|
28
|
+
expected = 'instructions.html'
|
29
|
+
actual = runner.output_filename
|
30
|
+
|
31
|
+
assert_equal expected, actual
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context '#generate_html!' do
|
37
|
+
context 'when options[:force] != true' do
|
38
|
+
should 'raise an exception if the output file exists' do
|
39
|
+
assert_raise(Markup::Runner::OutputExists) do
|
40
|
+
Markup::Runner.new(@source, :output => @output).generate_html!
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'create output file if it does not exist' do
|
45
|
+
new_output = File.dirname(__FILE__) + '/new_output.html'
|
46
|
+
assert !File.file?(new_output)
|
47
|
+
|
48
|
+
Markup::Runner.new(@source, :output => new_output).generate_html!
|
49
|
+
assert File.file?(new_output)
|
50
|
+
|
51
|
+
rm(new_output) if File.file?(new_output)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when options[:force] == true' do
|
56
|
+
should 'raise no exceptions, even when output file exists' do
|
57
|
+
assert_nothing_raised do
|
58
|
+
Markup::Runner.new(@source, :output => @output, :force => true).generate_html!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'overwrite contents of output file if it exists' do
|
63
|
+
old_contents = File.read(@output)
|
64
|
+
Markup::Runner.new(@source, :output => @output, :force => true).generate_html!
|
65
|
+
new_contents = File.read(@output)
|
66
|
+
|
67
|
+
assert new_contents != old_contents
|
68
|
+
assert new_contents =~ /^<h1>/, "New content doesn't seem to contain any HTML"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def clear_output_file!
|
74
|
+
File.open(@output, 'w') { |f| f.write nil }
|
75
|
+
end
|
76
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Wilding
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-16 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rdiscount
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.3.5
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thoughtbot-shoulda
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: redgreen
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: Small command line tool that reads Markdown files and outputs HTML
|
46
|
+
email: james@jameswilding.net
|
47
|
+
executables:
|
48
|
+
- markup
|
49
|
+
- markup
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- LICENSE
|
54
|
+
- README.markdown
|
55
|
+
files:
|
56
|
+
- bin/markup
|
57
|
+
- lib/markup.rb
|
58
|
+
- LICENSE
|
59
|
+
- README.markdown
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/jameswilding/markup
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Command line Markdown-to-HTML conversion
|
88
|
+
test_files:
|
89
|
+
- test/markup_test.rb
|
90
|
+
- test/test_helper.rb
|