ravicious-clothmark 0.2.0 → 0.2.1
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/README.rdoc +3 -2
- data/VERSION +1 -1
- data/bin/clothmark +12 -6
- data/clothmark.gemspec +1 -1
- data/lib/clothmark/module.rb +6 -6
- data/spec/clothmark/clothmark_spec.rb +47 -8
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -29,18 +29,19 @@ Quick example:
|
|
29
29
|
It converts the input file (bb_code.txt) to the HTML file (forum_post.html) using BBCode preprocessor.
|
30
30
|
|
31
31
|
Wanna see help? No problem.
|
32
|
-
|
33
32
|
$ clothmark -h
|
34
33
|
Usage: clothmark [options]
|
35
34
|
-h, --help Display this screen
|
36
35
|
-i, --input FILE Specify input file (if it aren't specified, then first argument will be used)
|
37
36
|
-o, --output FILE Specify output file
|
37
|
+
-ah, --additional-html Specify, do additional HTML and CSS will be used (default - false)
|
38
38
|
-m, --markup LANG Specify markup language (markdown, textile or bbcode, default is markdown)
|
39
39
|
|
40
|
-
So, there are
|
40
|
+
So, there are four arguments:
|
41
41
|
* -i or --input which specifies input file. If it isn't typed, then first argument will be used as an input file. This argument is required.
|
42
42
|
* -o or --output which specifies output file. You don't have to specify it, because ClothMark generates filename for output file automatically.
|
43
43
|
* -m or --markup which specifies markup language. If you don't specify it, then Markdown will be used as a choosed language.
|
44
|
+
* -ah or --additional-html which specifies, do additional HTML and CSS will be used. Default is set to false, but you can set it to true, just type this argument.
|
44
45
|
|
45
46
|
All files will be created in the folder that contains a input file, e.g:
|
46
47
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/bin/clothmark
CHANGED
@@ -18,12 +18,18 @@ optparse = OptionParser.new do |opts|
|
|
18
18
|
options[:input] = arg
|
19
19
|
end
|
20
20
|
|
21
|
-
# If output
|
21
|
+
# If output isn't specified, then it will be an empty string
|
22
22
|
options[:output] = ""
|
23
23
|
opts.on('-o', '--output FILE', 'Specify output file') do |arg|
|
24
24
|
options[:output] = arg || nil
|
25
25
|
end
|
26
26
|
|
27
|
+
# If this option isn't specified, then it will be false
|
28
|
+
options[:additional_html] = false
|
29
|
+
opts.on('-ah', '--additional-html', 'Specify, do additional HTML and CSS will be used (default - false)') do
|
30
|
+
options[:additional_html] = true
|
31
|
+
end
|
32
|
+
|
27
33
|
options[:markup] = "markdown"
|
28
34
|
opts.on('-m', '--markup LANG', %w(markdown textile bbcode) ,'Specify markup language (markdown, textile or bbcode, default is markdown)') do |arg|
|
29
35
|
options[:markup] = arg.downcase || "markdown"
|
@@ -36,22 +42,22 @@ begin
|
|
36
42
|
rescue OptionParser::MissingArgument => e
|
37
43
|
puts e
|
38
44
|
puts "To see help, type:"
|
39
|
-
puts "$
|
45
|
+
puts "$ #{File.basename(__FILE__)} -h"
|
40
46
|
exit
|
41
47
|
rescue OptionParser::InvalidArgument => e
|
42
48
|
puts e
|
43
49
|
puts "To see accepted arguments, type:"
|
44
|
-
puts "$
|
50
|
+
puts "$ #{File.basename(__FILE__)} -h"
|
45
51
|
exit
|
46
52
|
end #begin
|
47
53
|
|
48
54
|
case options[:markup]
|
49
55
|
when 'markdown'
|
50
|
-
@cloth = BlueMark.new(options[:input], options[:output])
|
56
|
+
@cloth = BlueMark.new(options[:input], options[:output], options[:additional_html])
|
51
57
|
when 'textile'
|
52
|
-
@cloth = RedMark.new(options[:input], options[:output])
|
58
|
+
@cloth = RedMark.new(options[:input], options[:output], options[:additional_html])
|
53
59
|
when 'bbcode'
|
54
|
-
@cloth = BBMark.new(options[:input], options[:output])
|
60
|
+
@cloth = BBMark.new(options[:input], options[:output], options[:additional_html])
|
55
61
|
end
|
56
62
|
|
57
63
|
@cloth.convert
|
data/clothmark.gemspec
CHANGED
data/lib/clothmark/module.rb
CHANGED
@@ -5,7 +5,7 @@ module ClothMark
|
|
5
5
|
HEADER = <<-EOF
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
|
8
|
+
<style type="text/css">
|
9
9
|
#wrapper {
|
10
10
|
width: 600px; margin: 0 auto;
|
11
11
|
font-family: "Trebuchet MS", Verdana, sans-serif;
|
@@ -33,7 +33,7 @@ module ClothMark
|
|
33
33
|
<body>
|
34
34
|
<div id="wrapper">
|
35
35
|
EOF
|
36
|
-
|
36
|
+
|
37
37
|
# Footer for an output file.
|
38
38
|
FOOTER = <<-EOF
|
39
39
|
</div>
|
@@ -42,7 +42,7 @@ module ClothMark
|
|
42
42
|
EOF
|
43
43
|
|
44
44
|
# ClothMark will generate a default filename if user don't want to save output to a specific file.
|
45
|
-
def initialize(file, output = nil)
|
45
|
+
def initialize(file, output = nil, additional_html = true)
|
46
46
|
@file = file
|
47
47
|
if (!output || output.empty?)
|
48
48
|
@output = "#{file.gsub(/(\.[a-z]{3,4})/, '')}_clothmark.html"
|
@@ -50,15 +50,15 @@ module ClothMark
|
|
50
50
|
@output = output
|
51
51
|
end
|
52
52
|
@data_for_output = []
|
53
|
+
@additional_html = additional_html # If true, then ClothMark will generate additional CSS and HTML
|
53
54
|
end
|
54
55
|
|
55
56
|
# Saves output to a file (one paragraph per line).
|
56
57
|
def save_to_file
|
57
58
|
File.open(@output, 'w+') do |file|
|
58
|
-
file.puts HEADER
|
59
|
+
file.puts HEADER if @additional_html
|
59
60
|
file.puts @data_for_output.join("\n")
|
60
|
-
|
61
|
-
file.puts FOOTER
|
61
|
+
file.puts FOOTER if @additional_html
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -10,40 +10,79 @@ describe ClothMark do
|
|
10
10
|
@foo.output.should == 'nothing_special_clothmark.html'
|
11
11
|
end
|
12
12
|
|
13
|
-
it "should gets output if it is specified" do
|
13
|
+
it "should gets output filename if it is specified" do
|
14
14
|
@bar = @klass.new('rails.txt', 'rubyonrails.txt')
|
15
15
|
@bar.output.should == 'rubyonrails.txt'
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should save data
|
19
|
-
|
18
|
+
it "should save valid data (one paragraph per line)" do
|
19
|
+
@foo.data_for_output = ['Donec ultrices tortor non lorem egestas ut pharetra diam vestibulum.',
|
20
20
|
'Etiam magna urna, porta non scelerisque ut, porttitor non purus.',
|
21
21
|
'Mauris blandit dui ac eros varius quis lacinia velit semper.']
|
22
22
|
|
23
23
|
@foo.save_to_file
|
24
24
|
|
25
25
|
counter = 0
|
26
|
-
test_string = ''
|
27
26
|
|
28
27
|
File.open(@foo.output, 'r') do |file|
|
29
28
|
# There's more than one paragraph in 'input file' (data_for_output),
|
30
29
|
# so we wan't a few paragraphs also in 'output' file.
|
31
30
|
file.each_line do |line|
|
32
31
|
counter += 1 unless line.empty?
|
33
|
-
test_string << "#{line} \n"
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
37
35
|
# File should have at least two paragraphs
|
38
36
|
counter.should > 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should save data for output to the output file with additional CSS and HTML" do
|
40
|
+
@foo.data_for_output = ["OH MY!"]
|
41
|
+
@foo.save_to_file
|
42
|
+
|
43
|
+
test_string = ''
|
39
44
|
|
45
|
+
# Puts each file from output to string for test
|
46
|
+
File.open(@foo.output, 'r') do |file|
|
47
|
+
file.each_line do |line|
|
48
|
+
test_string << "#{line} \n"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Additional HTML and CSS should be added
|
40
53
|
test_string.should match(/<html/)
|
41
54
|
test_string.should match(/<head/)
|
55
|
+
test_string.should match(/<style/)
|
42
56
|
test_string.should match(/<body/)
|
43
57
|
end
|
44
|
-
|
58
|
+
|
59
|
+
it "should save data for output to the output file without additional HTML and CSS" do
|
60
|
+
|
61
|
+
@egg = @klass.new('example.txt', nil, false)
|
62
|
+
|
63
|
+
@egg.data_for_output = ["OH MY!"]
|
64
|
+
@egg.save_to_file
|
65
|
+
|
66
|
+
test_string = ''
|
67
|
+
|
68
|
+
# Puts each file from output to string for test
|
69
|
+
File.open(@egg.output, 'r') do |file|
|
70
|
+
file.each_line do |line|
|
71
|
+
test_string << "#{line} \n"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Additional HTML and CSS should not be added
|
76
|
+
test_string.should_not match(/<html/)
|
77
|
+
test_string.should_not match(/<head/)
|
78
|
+
test_string.should_not match(/<style/)
|
79
|
+
test_string.should_not match(/<body/)
|
80
|
+
end
|
81
|
+
|
45
82
|
after :all do
|
46
|
-
# Remove
|
47
|
-
|
83
|
+
# Remove testfiles (outputs)
|
84
|
+
[@foo.output, @egg.output].each do |file|
|
85
|
+
FileUtils.rm(file)
|
86
|
+
end
|
48
87
|
end
|
49
88
|
end
|