Class: RackRscript
Instance Method Summary collapse
- #call(env) ⇒ Object
- #clear_cache ⇒ Object
- #haml(name, options = {}) ⇒ Object
-
#initialize(log: nil, pkg_src: '', cache: 5, rsc_host: 'rse', rsc_package_src: nil, pxlinks: nil, debug: false, root: 'www', static: []) ⇒ RackRscript
constructor
A new instance of RackRscript.
- #redirect(url) ⇒ Object
- #run_job(url, jobs, params = {}, *qargs) ⇒ Object
- #slim(name, options = {}) ⇒ Object
-
#transform(xsl, xml) ⇒ Object
jr 140616 not yet used and still needs to be tested.
Constructor Details
#initialize(log: nil, pkg_src: '', cache: 5, rsc_host: 'rse', rsc_package_src: nil, pxlinks: nil, debug: false, root: 'www', static: []) ⇒ RackRscript
Returns a new instance of RackRscript.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rack-rscript.rb', line 33 def initialize(log: nil, pkg_src: '', cache: 5, rsc_host: 'rse', rsc_package_src: nil, pxlinks: nil, debug: false, root: 'www', static: []) @log, @debug, @static = log, debug, static puts '@app_root: ' + @app_root.inspect if @debug puts 'root: ' + root.inspect if @debug @params = {} @templates = {} @rrscript = RScript.new log: log, pkg_src: pkg_src, cache: cache @url_base = pkg_src # web server serving the RSF files @url_base += '/' unless @url_base[-1] == '/' if pxlinks then src, _ = RXFHelper.read(pxlinks) if src =~ /^<\?/ then @pxlinks = PolyrexLinks.new src else @pxlinks = PolyrexLinks.new @pxlinks.parse pxlinks end end super() # required for app-routes initialize method to exectue default_routes(@env, @params) @rsc = nil @rsc = RSC.new rsc_host, rsc_package_src if rsc_package_src @filetype = {xml: 'application/xml', html: 'text/html', png: 'image/png', jpg: 'image/jpeg', txt: 'text/plain', css: 'text/css', xsl: 'application/xml', svg: 'image/svg+xml'} @root, @static = root, static end |
Instance Method Details
#call(env) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rack-rscript.rb', line 82 def call(env) @env = env raw_request = env['REQUEST_URI'][/https?:\/\/[^\/]+(.*)/,1] @log.info 'RackRscript/call: ' + env.inspect if @log @req = Rack::Request.new(env) @req_params = @req.params default_routes(env,@params) request = if @pxlinks then found = @pxlinks.locate(raw_request) found ? found.join : raw_request else raw_request end run_request(request) end |
#clear_cache ⇒ Object
103 104 105 |
# File 'lib/rack-rscript.rb', line 103 def clear_cache() @rrscript.reset end |
#haml(name, options = {}) ⇒ Object
157 158 159 |
# File 'lib/rack-rscript.rb', line 157 def haml(name,={}) render name, :haml, end |
#redirect(url) ⇒ Object
148 149 150 |
# File 'lib/rack-rscript.rb', line 148 def redirect(url) Redirect.new url end |
#run_job(url, jobs, params = {}, *qargs) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rack-rscript.rb', line 107 def run_job(url, jobs, params={}, *qargs) if @params[:splat] then @params.each do |k,v| @params.delete k unless k == :splat or k == :package \ or k == :job or k == :captures end end if @params[:splat] and @params[:splat].length > 0 then h = @params[:splat].first[1..-1].split('&').inject({}) do |r,x| k, v = x.split('=') v ? r.merge(k[/\w+$/].to_sym => Rack::Utils.unescape(v)) : r end @params.merge! h end @params.merge! @req.params result, args = @rrscript.read([url, jobs.split(/\s/), \ qargs].flatten) rws = self rsc = @rsc if @rsc req = @req if @req begin r = eval result return r rescue Exception => e @params = {} err_label = e..to_s + " :: \n" + e.backtrace.join("\n") raise RackRscriptError, err_label @log.debug 'RackRscript/run_job/error: ' + err_label if @log end end |
#slim(name, options = {}) ⇒ Object
161 162 163 |
# File 'lib/rack-rscript.rb', line 161 def slim(name,={}) render name, :slim, end |
#transform(xsl, xml) ⇒ Object
jr 140616 not yet used and still needs to be tested
153 154 155 |
# File 'lib/rack-rscript.rb', line 153 def transform(xsl, xml) Rexslt.new(xsl, xml).to_s end |