Permalink
Browse files

adds the ability to pash options to the api

  • Loading branch information...
1 parent 7dcdc3e commit 384ef899583c5f5955b7d49be4e61c0f198173c1 @itsthatguy itsthatguy committed Aug 12, 2014
Showing with 12 additions and 5 deletions.
  1. +12 −5 server.rb
View
@@ -31,21 +31,28 @@
begin
res = Crack::JSON.parse(request.body.read.to_s)
@html = res["page"]["html"]
- @haml = convert(@html)
+ options = res["options"] || {}
+ @haml = convert(@html, options)
{ :page => {:html => @html, :haml => @haml}}.to_json
rescue
{ :status => :error, :message => 'unable to parse json'}.to_json
end
end
-
post "/*" do
@html = params["page"]["html"]
@haml = convert(@html)
haml :index
end
-def convert(html)
- Html2haml::HTML.new(html, :erb => true, :xhtml => false,
- :ruby19_style_attributes => true).render
+def symbolize_keys(hash)
+ hash.reduce({}) do |memo, (key, value)|
+ memo[key.to_sym] = value
+ memo
+ end
+end
+
+def convert(html, options = {})
+ options = {:erb => true, :xhtml => false}.merge(symbolize_keys(options))
+ Html2haml::HTML.new(html, options).render
end

0 comments on commit 384ef89

Please sign in to comment.