Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LQDN Adminsys
amendments
Commits
915b73a4
Commit
915b73a4
authored
Mar 31, 2013
by
Michael Witrant
Browse files
accept template as option
parent
74a3682c
Changes
2
Hide whitespace changes
Inline
Side-by-side
extract_amendments.rb
View file @
915b73a4
...
...
@@ -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
...
...
server.rb
View file @
915b73a4
...
...
@@ -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)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment