Commit 915b73a4 authored by Michael Witrant's avatar Michael Witrant

accept template as option

parent 74a3682c
......@@ -147,9 +147,10 @@ class AmendmentExtractor
end
debug "rendering amendments"
template = ERB.new File.read('template.erb'), nil, '-'
template_text = options[:template] || File.read('template.erb')
template = ERB.new template_text, 4, '-'
erb_binding = OpenStruct.new(amendments: amendments).instance_eval { binding }
erb_binding = OpenStruct.new(amendments: amendments).instance_eval { binding }.taint
output = template.result(erb_binding)
end
end
......@@ -157,10 +158,11 @@ end
if $0 == __FILE__
options = {}
extra_args = cli '--xml-dump' => lambda { |path| options[:xml_dump_path] = path },
'-d --debug' => lambda { $DEBUG = true },
'-1 --one' => lambda { options[:parse_only_one] = true },
'-n --number' => lambda { |num| options[:parse_only_num] = num }
extra_args = cli '--xml-dump' => lambda { |path| options[:xml_dump_path] = path },
'-d --debug' => lambda { $DEBUG = true },
'-1 --one' => lambda { options[:parse_only_one] = true },
'-n --number' => lambda { |num| options[:parse_only_num] = num },
'-t --template' => lambda { |file| options[:template] = File.read(file) }
opendocument_path = extra_args.first
raise "usage: #$0 <OpenDocument file>" unless opendocument_path
......
......@@ -12,7 +12,7 @@ get '/' do
end
post '/extract' do
result = AmendmentExtractor.new.extract(params['file'][:tempfile].path)
result = AmendmentExtractor.new.extract(params['file'][:tempfile].path, template: params['template'])
haml :extract, locals: {result: result}
end
......@@ -39,9 +39,13 @@ __END__
%label.control-label{:for => "file"} ODT File
.controls
%input#file{type: "file", name: "file"}
.control-group
%label.control-label{:for => "template"} Template
.controls
%textarea.input-block-level#template{rows: 20, name: "template"}= params[:template] || File.read('template.erb')
.control-group
.controls
%button.btn.btn-primary{:type => "submit"} Extract
@@ extract
%textarea{rows: 20, style: 'width: 100%'}= Rack::Utils.escape_html(result)
%textarea.input-block-level{rows: 20}= Rack::Utils.escape_html(result)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment