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.
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 226 227 228 229 230 231 232 |
# File 'lib/rdf/distiller/application.rb', line 199 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] 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
142 143 144 145 146 147 |
# File 'lib/rdf/distiller/application.rb', line 142 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
239 240 241 242 243 |
# File 'lib/rdf/distiller/application.rb', line 239 post '/distiller' do payload = Sinatra::IndifferentHash.new.merge(::JSON.parse(request.body.read)) content_type :json distil(payload).to_json end |