60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/lilp/base.rb', line 60
def run( params, files_path )
lilp_parser = Redcarpet::Markdown.new(LiterateRender,
:fenced_code_blocks => true)
files_path.each do |file_path|
puts "#{file_path}: "
if File.extname( file_path ) != '.md'
puts 'Skipping (file must have a .md extension)'
next
end
output_path = String.new
if params[:output]
if File.exists?(params[:output])
puts "Folder #{params[:output]} already exists"
else
puts "Creating folder #{params[:output]}"
Dir.mkdir(params[:output])
end
file_name = File.basename(file_path).chomp(
File.extname(file_path) )
output_path = File.join(params[:output], file_name)
else
output_path = file_path.chomp( File.extname(file_path) )
end
begin
file = File.open( file_path, 'r' )
out = File.open( output_path, 'w' )
out.write( lilp_parser.render( file.read ) )
out.close
file.close
puts "Wrote #{output_path}"
rescue
puts "Error while parsing file '#{file_path}': #{$!}"
end
end
end
|