hamdown 0.0.6 → 0.0.7
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/bin/hamdown +5 -2
- data/lib/hamdown.rb +27 -3
- metadata +3 -3
data/bin/hamdown
CHANGED
@@ -3,9 +3,12 @@
|
|
3
3
|
# Convert a file from markdown to html wrapped in a haml layout
|
4
4
|
|
5
5
|
require 'hamdown'
|
6
|
+
require 'trollop'
|
6
7
|
|
7
|
-
options =
|
8
|
-
|
8
|
+
options = Trollop::options do
|
9
|
+
opt :file_path, "File path", :type => :string
|
10
|
+
opt :columns, "Output in columns"
|
11
|
+
end
|
9
12
|
|
10
13
|
hdown = Hamdown.new(options)
|
11
14
|
puts hdown.to_html
|
data/lib/hamdown.rb
CHANGED
@@ -5,12 +5,36 @@ require 'haml'
|
|
5
5
|
class Hamdown
|
6
6
|
def initialize(options={})
|
7
7
|
file = options.delete(:file_path) { raise "you need to specify a file name" }
|
8
|
-
@innerfile =
|
8
|
+
@innerfile = File.open(file).read
|
9
9
|
@outerfile = File.open('layout.haml')
|
10
10
|
end
|
11
11
|
|
12
|
-
def to_html
|
13
|
-
|
12
|
+
def to_html(options={})
|
13
|
+
columns = options.delete(:columns) { false }
|
14
|
+
if columns
|
15
|
+
first_half = ""
|
16
|
+
second_half = ""
|
17
|
+
line_count = (@innerfile.lines.count / 2.0).ceil
|
18
|
+
blank_line = ""
|
19
|
+
@innerfile.each_with_index do |line, index|
|
20
|
+
if index < line_count
|
21
|
+
first_half << line
|
22
|
+
blank_line = line.match(/^\s*$/) if index = line_count - 1
|
23
|
+
elsif index == line_count && !blank_line
|
24
|
+
first_half << line
|
25
|
+
else
|
26
|
+
second_half << line
|
27
|
+
end
|
28
|
+
end
|
29
|
+
html = "<table><tr><td>\n"
|
30
|
+
html << RDiscount.new(first_half).to_html
|
31
|
+
html << "</td>\n<td>\n"
|
32
|
+
html << RDiscount.new(second_half).to_html
|
33
|
+
html << "</td></tr></table>"
|
34
|
+
else
|
35
|
+
html = RDiscount.new(@innerfile).to_html
|
36
|
+
end
|
37
|
+
Haml::Engine.new(@outerfile.read).render { html }
|
14
38
|
end
|
15
39
|
|
16
40
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Robert Fletcher
|