Class: RDF::Distiller::Application
- Defined in:
- lib/rdf/distiller/application.rb
Constant Summary collapse
Instance Method Summary collapse
-
#get("/distiller", params) ⇒ Object
Get "/distiller" either returns the main distiller page or distilled markup.
-
#get("/", params) ⇒ Object
Get "/" either returns the main linter page or linted markup.
-
#post("/distiller", params) ⇒ Object
POST "/distiller" returns distilled markup as JSON.
Instance Method Details
#get("/distiller", params) ⇒ Object
Get "/distiller" either returns the main distiller page or distilled markup.
When JSON is requested, returns data intended for the single-page application.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/rdf/distiller/application.rb', line 192 get '/distiller' do set_cache_header if request.accept?('text/html') && !params.has_key?('raw') raw_opt = { symbol: :raw, control: :checkbox, description: "Return raw results directly through the browser (use link at bottom of the page)." } # Return application erb :distiller, locals: { head: :distiller, root: url("/"), title: "Ruby Distiller", command_data: RDF::CLI.commands(format: :json).to_json, option_data: RDF::CLI.([], format: :json).unshift(raw_opt).to_json, input_format_option_data: RDF::Reader.each.inject({}) {|memo, r| memo.merge(r.to_sym => r..map(&:to_hash))}.to_json, output_format_option_data: RDF::Writer.each.inject({}) {|memo, w| memo.merge(w.to_sym => w..map(&:to_hash))}.to_json } elsif request.accept?('application/json') && request.xhr? && !params.has_key?('raw') # Return distilled input content_type :json distil(params).to_json else # Return raw content hash = distil(params) if hash[:format] negotiated_format hash[:format] hash[:serialized] else content_type :txt hash[:messages][:error].join("\n") end end end |
#get("/", params) ⇒ Object
Get "/" either returns the main linter page or linted markup
135 136 137 138 139 140 |
# File 'lib/rdf/distiller/application.rb', line 135 get '/' do cache_control :public, :must_revalidate, max_age: 60 result = erb :index, locals: {title: "Ruby Linked Data Service"} etag result.hash result end |
#post("/distiller", params) ⇒ Object
POST "/distiller" returns distilled markup as JSON
232 233 234 235 236 |
# File 'lib/rdf/distiller/application.rb', line 232 post '/distiller' do payload = Sinatra::IndifferentHash.new.merge(::JSON.parse(request.body.read)) content_type :json distil(payload).to_json end |