murdoc 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/murdoc +6 -2
- data/lib/murdoc.rb +4 -3
- data/lib/murdoc/annotator.rb +16 -3
- data/lib/murdoc/paragraph.rb +4 -2
- data/murdoc.gemspec +1 -1
- data/spec/murdoc/annotator_spec.rb +4 -0
- data/spec/murdoc/paragraph_spec.rb +4 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bin/murdoc
CHANGED
@@ -3,11 +3,15 @@ require "optparse"
|
|
3
3
|
$: << "./lib/"
|
4
4
|
require "murdoc"
|
5
5
|
|
6
|
-
|
6
|
+
options = {}
|
7
7
|
|
8
8
|
option_parser = OptionParser.new do |opts|
|
9
9
|
opts.banner = "murdoc <input file> <output html>"
|
10
10
|
|
11
|
+
opts.on("--[no-]syntax-highlight", "Highlight syntax using pygments") do |h|
|
12
|
+
options[:highlight_source] = h
|
13
|
+
end
|
14
|
+
|
11
15
|
opts.on_tail("-h", "--help", "Show this message") do
|
12
16
|
puts opts
|
13
17
|
exit
|
@@ -20,5 +24,5 @@ option_parser.parse!
|
|
20
24
|
if ARGV.size < 2
|
21
25
|
puts option_parser
|
22
26
|
else
|
23
|
-
Murdoc.generate_from_file(ARGV[0], ARGV[1])
|
27
|
+
Murdoc.generate_from_file(ARGV[0], ARGV[1], options)
|
24
28
|
end
|
data/lib/murdoc.rb
CHANGED
@@ -10,10 +10,11 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
module Murdoc
|
13
|
-
def self.generate_from_file(input, output)
|
14
|
-
annotator = Annotator.from_file(input)
|
13
|
+
def self.generate_from_file(input, output, options = {})
|
14
|
+
annotator = Annotator.from_file(input, nil, options)
|
15
|
+
markup_dir = File.dirname(__FILE__)+ "/../markup"
|
15
16
|
File.open(output, "w+") do |f|
|
16
|
-
f.puts Formatter.new("
|
17
|
+
f.puts Formatter.new("#{markup_dir}/template.haml").render(:paragraphs => annotator.paragraphs, :stylesheet => File.read("#{markup_dir}/stylesheet.css"))
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/lib/murdoc/annotator.rb
CHANGED
@@ -8,18 +8,31 @@ module Murdoc
|
|
8
8
|
# Attribute accessor containing the resulting paragraphs
|
9
9
|
attr_accessor :paragraphs
|
10
10
|
|
11
|
+
# Options
|
12
|
+
# Available options:
|
13
|
+
# `:highlight_source` -- highlights source syntax using pygments (default: true)
|
14
|
+
attr_accessor :options
|
15
|
+
|
16
|
+
def self.default_options
|
17
|
+
{
|
18
|
+
:highlight_source => true
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
11
22
|
|
12
23
|
# `source` string contains annotated source code
|
13
24
|
# `source_type` is one of supported source types (currently `[:ruby, :javascript]`)
|
14
|
-
def initialize(source, source_type)
|
25
|
+
def initialize(source, source_type, options = {})
|
15
26
|
self.source_type = source_type
|
16
27
|
self.source = source
|
28
|
+
self.options = self.class.default_options.merge(options)
|
17
29
|
end
|
18
30
|
|
31
|
+
|
19
32
|
# You may also initialize annotator from file, it will even try to detect the
|
20
33
|
# source type from extension.
|
21
|
-
def self.from_file(filename, source_type = nil)
|
22
|
-
self.new(File.read(filename), source_type || detect_source_type_from_filename(filename))
|
34
|
+
def self.from_file(filename, source_type = nil, options = {})
|
35
|
+
self.new(File.read(filename), source_type || detect_source_type_from_filename(filename), options)
|
23
36
|
end
|
24
37
|
|
25
38
|
def source_type
|
data/lib/murdoc/paragraph.rb
CHANGED
@@ -9,12 +9,14 @@ module Murdoc
|
|
9
9
|
attr_accessor :annotation
|
10
10
|
attr_accessor :source_type
|
11
11
|
attr_accessor :starting_line
|
12
|
+
attr_accessor :options
|
12
13
|
|
13
|
-
def initialize(source, annotation, starting_line = 0, source_type = nil)
|
14
|
+
def initialize(source, annotation, starting_line = 0, source_type = nil, options ={})
|
14
15
|
self.source = source
|
15
16
|
self.annotation = annotation
|
16
17
|
self.starting_line = starting_line
|
17
18
|
self.source_type = source_type
|
19
|
+
self.options = options
|
18
20
|
end
|
19
21
|
|
20
22
|
def source_type
|
@@ -31,7 +33,7 @@ module Murdoc
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def formatted_source
|
34
|
-
@formatted_source ||= if pygments_installed?
|
36
|
+
@formatted_source ||= if pygments_installed? && options[:highlight_source]
|
35
37
|
IO.popen("pygmentize -l #{source_type} -f html", "w+") do |pipe|
|
36
38
|
pipe.puts source
|
37
39
|
pipe.close_write
|
data/murdoc.gemspec
CHANGED
@@ -11,6 +11,10 @@ describe Murdoc::Annotator do
|
|
11
11
|
Murdoc::Annotator.new("# Hello", "ruby").source_type.should == "ruby"
|
12
12
|
Murdoc::Annotator.new("# Hello", :ruby).source_type.should == "ruby"
|
13
13
|
end
|
14
|
+
|
15
|
+
it "should set options from hash" do
|
16
|
+
Murdoc::Annotator.new("", "", :foo => :bar).options[:foo].should == :bar
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
describe ".from_file" do
|
@@ -17,5 +17,9 @@ describe Murdoc::Paragraph do
|
|
17
17
|
it "should optionally set starting line" do
|
18
18
|
described_class.new("", "", 666, :ruby).starting_line.should == 666
|
19
19
|
end
|
20
|
+
|
21
|
+
it "should optionally set options" do
|
22
|
+
described_class.new("", "", 666, :ruby, {:foo => :bar}).options.should == {:foo => :bar}
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
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
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mark Abramov
|
@@ -166,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
166
|
requirements:
|
167
167
|
- - ">="
|
168
168
|
- !ruby/object:Gem::Version
|
169
|
-
hash:
|
169
|
+
hash: 4042360241948241742
|
170
170
|
segments:
|
171
171
|
- 0
|
172
172
|
version: "0"
|