lilp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lilp/base.rb +26 -26
- data/lib/lilp/version.rb +1 -1
- metadata +2 -2
data/lib/lilp/base.rb
CHANGED
@@ -15,26 +15,26 @@
|
|
15
15
|
# Let's define here our render. It is a class that inherite from Redcarpet::Render::Base
|
16
16
|
# class LiterateRender < Redcarpet::Render::Base
|
17
17
|
# COMMENT_SIGN = "# "
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# Now, redcarpet's parser will call a number of hook, depending on what has been found
|
20
20
|
# in the given lilp file. These hooks can be either `header`, `paragraph`, `block_code`
|
21
|
-
# or other. Here is the formal specification:
|
21
|
+
# or other. Here is the formal specification:
|
22
22
|
# def preprocess(full_document)
|
23
23
|
# @macro = {}
|
24
24
|
# full_document
|
25
25
|
# end
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# def header(text, header_level)
|
28
28
|
# if header_level == 3
|
29
29
|
# @macro[$1.to_sym] if text =~ /Call\: (.*)/
|
30
30
|
# end
|
31
31
|
# end
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# def paragraph(text)
|
34
34
|
# text += "\n"
|
35
35
|
# text.gsub(/^/, COMMENT_SIGN)
|
36
36
|
# end
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# def block_code(code, language)
|
39
39
|
# if @define_macro and @current_macro
|
40
40
|
# @macro[@current_macro] = code += "\n"
|
@@ -43,19 +43,19 @@
|
|
43
43
|
# code += "\n"
|
44
44
|
# end
|
45
45
|
# end
|
46
|
-
#
|
46
|
+
#
|
47
47
|
# def hrule()
|
48
48
|
# @define_macro = ( not @define_macro )
|
49
49
|
# @current_macro = nil if @define_macro
|
50
50
|
# end
|
51
|
-
#
|
51
|
+
#
|
52
52
|
# def emphasis(text)
|
53
53
|
# @current_macro = text.to_sym if @define_macro
|
54
54
|
# nil
|
55
55
|
# end
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# end
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# The code above lists all the rules our render will live by. If there is anything to
|
60
60
|
# change in our render, it's in this part of the code.
|
61
61
|
# To a regular user, lilp is only a command he can invoke from the terminal. In order
|
@@ -67,16 +67,16 @@
|
|
67
67
|
# _The option parser_
|
68
68
|
# class Option
|
69
69
|
# attr_reader :files, :params
|
70
|
-
#
|
70
|
+
#
|
71
71
|
# def initialize( args )
|
72
72
|
# @params = {}
|
73
73
|
# @parser = OptionParser.new
|
74
74
|
# @args = args
|
75
|
-
#
|
75
|
+
#
|
76
76
|
# @parser.banner = "Usage: lilp file_name.pl [other_file.pl] [-o output_dir]"
|
77
77
|
# @parser.on("-o", "--output D", String, "Output directory") { |val| @params[:output] = File.join('.', "#{val}") }
|
78
78
|
# end
|
79
|
-
#
|
79
|
+
#
|
80
80
|
# def parse
|
81
81
|
# begin
|
82
82
|
# @files = @parser.parse(@args)
|
@@ -96,7 +96,7 @@
|
|
96
96
|
# end
|
97
97
|
# end
|
98
98
|
# end
|
99
|
-
#
|
99
|
+
#
|
100
100
|
# We have a lilp render class, an option class that takes care of the command line
|
101
101
|
# options, now we need a way to tie the to together.
|
102
102
|
# To do this, let's create a third object. The class will be "Runner". It's goal
|
@@ -104,18 +104,18 @@
|
|
104
104
|
# the command line.
|
105
105
|
# _Runner class_
|
106
106
|
# class Runner
|
107
|
-
#
|
107
|
+
#
|
108
108
|
# def run( params, files_path )
|
109
109
|
# lilp_parser = Redcarpet::Markdown.new(LiterateRender, :fenced_code_blocks => true)
|
110
|
-
#
|
110
|
+
#
|
111
111
|
# files_path.each do |file_path|
|
112
112
|
# puts "#{file_path}: "
|
113
|
-
#
|
113
|
+
#
|
114
114
|
# if File.extname( file_path ) != '.md'
|
115
115
|
# puts 'Skipping (file must have a .lp extension)'
|
116
116
|
# next
|
117
117
|
# end
|
118
|
-
#
|
118
|
+
#
|
119
119
|
# output_path = String.new
|
120
120
|
# if params[:output]
|
121
121
|
# # Creates the output directory if it doesn't exist
|
@@ -125,32 +125,32 @@
|
|
125
125
|
# puts "Creating folder #{params[:output]}"
|
126
126
|
# Dir.mkdir(params[:output])
|
127
127
|
# end
|
128
|
-
#
|
128
|
+
#
|
129
129
|
# file_name = File.basename(file_path).chomp( File.extname(file_path) )
|
130
130
|
# output_path = File.join(params[:output], file_name)
|
131
131
|
# else
|
132
132
|
# output_path = file_path.chomp( File.extname(file_path) )
|
133
133
|
# end
|
134
|
-
#
|
134
|
+
#
|
135
135
|
# begin
|
136
136
|
# file = File.open( file_path, 'r' )
|
137
137
|
# out = File.open( output_path, 'w' )
|
138
|
-
#
|
138
|
+
#
|
139
139
|
# out.write( lilp_parser.render( file.read ) )
|
140
|
-
#
|
140
|
+
#
|
141
141
|
# out.close
|
142
142
|
# file.close
|
143
|
-
#
|
143
|
+
#
|
144
144
|
# puts "Wrote #{output_path}"
|
145
|
-
#
|
145
|
+
#
|
146
146
|
# rescue
|
147
147
|
# puts "Error while parsing file '#{file_path}': #{$!}"
|
148
148
|
# end
|
149
149
|
# end
|
150
|
-
#
|
150
|
+
#
|
151
151
|
# end
|
152
152
|
# end
|
153
|
-
#
|
153
|
+
#
|
154
154
|
# Now, the last thing we need to do is to attach each of the parts in the correct order, under
|
155
155
|
# the Lilp module.
|
156
156
|
module Lilp
|
@@ -236,7 +236,7 @@ class Runner
|
|
236
236
|
puts "#{file_path}: "
|
237
237
|
|
238
238
|
if File.extname( file_path ) != '.md'
|
239
|
-
puts 'Skipping (file must have a .
|
239
|
+
puts 'Skipping (file must have a .md extension)'
|
240
240
|
next
|
241
241
|
end
|
242
242
|
|
data/lib/lilp/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: lilp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael Sokol
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-17 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redcarpet
|