Sha256: 58c4976f13d842c47f047d3e1289f409ba0015462055f56ea46a713f48fb7b92
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require 'sinatra' require 'rack-flash' require 'sinatra/reloader' require 'moxy/sandbox_eval' module Moxy class App < Sinatra::Base filedir = File.dirname(__FILE__) set :public_folder, File.expand_path("../../public", filedir) set :views, File.expand_path("../../views", filedir) enable :sessions use Rack::Flash configure(:development) do register Sinatra::Reloader end helpers do include Rack::Utils alias_method :h, :escape_html def current_section url_path request.path_info.sub('/','').split('/')[0].downcase end def current_page url_path request.path_info.sub('/','') end def url_path(*path_parts) [ path_prefix, path_parts ].join("/").squeeze('/') end alias_method :u, :url_path def path_prefix request.env['SCRIPT_NAME'] end end get '/reset' do WebMock.reset! redirect path_prefix end get '/current' do @reqs = WebMock::StubRegistry.instance.request_stubs.each { |r| r.to_s } || [] erb :current end get '/' do @numreqs = WebMock::StubRegistry.instance.request_stubs.size erb :editor end post '/' do flag, res = SandboxEval.new(development?).evaluate(params[:mock_text]) if params[:mock_text] if(flag == :ok) flash[:notice] = "Your request #{res} have been registered." elsif flash[:error] = "Error registering this request: #{res}" headers 'x-moxy-errors' => "#{flag}: #{res}" end redirect path_prefix end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
moxy-0.0.1 | lib/moxy/app.rb |