Class: KnjEruby
- Includes:
- Erubis::StdoutEnhancer
- Defined in:
- lib/knj/erb/include.rb
Class Method Summary collapse
- .connect(signal, &block) ⇒ Object
- .connects ⇒ Object
- .fcgi ⇒ Object
- .fcgi=(newvalue) ⇒ Object
- .filepath ⇒ Object
- .has_status_header? ⇒ Boolean
- .header(key, value) ⇒ Object
- .headers ⇒ Object
- .load(filename, args = {}) ⇒ Object
- .load_return(filename, args = {}) ⇒ Object
- .print_headers(args = {}) ⇒ Object
- .printcont(tmp_out, args = {}) ⇒ Object
- .reset_connects ⇒ Object
- .reset_headers ⇒ Object
Class Method Details
.connect(signal, &block) ⇒ Object
148 149 150 151 |
# File 'lib/knj/erb/include.rb', line 148 def self.connect(signal, &block) @connects[signal] = [] if !@connects[signal] @connects[signal] << block end |
.connects ⇒ Object
105 |
# File 'lib/knj/erb/include.rb', line 105 def self.connects; return @connects; end |
.fcgi ⇒ Object
104 |
# File 'lib/knj/erb/include.rb', line 104 def self.fcgi; return @fcgi; end |
.fcgi=(newvalue) ⇒ Object
103 |
# File 'lib/knj/erb/include.rb', line 103 def self.fcgi=(newvalue); @fcgi = newvalue; end |
.filepath ⇒ Object
144 145 146 |
# File 'lib/knj/erb/include.rb', line 144 def self.filepath return @filepath end |
.has_status_header? ⇒ Boolean
120 121 122 123 124 125 126 127 128 |
# File 'lib/knj/erb/include.rb', line 120 def self.has_status_header? @headers.each do |header| if header[0] == "Status" return true end end return false end |
.header(key, value) ⇒ Object
140 141 142 |
# File 'lib/knj/erb/include.rb', line 140 def self.header(key, value) @headers << [key, value] end |
.headers ⇒ Object
106 |
# File 'lib/knj/erb/include.rb', line 106 def self.headers; return @headers; end |
.load(filename, args = {}) ⇒ Object
189 190 191 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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/knj/erb/include.rb', line 189 def self.load(filename, args = {}) begin if !args[:custom_io] tmp_out = StringIO.new $stdout = tmp_out end ERuby.import(filename) if KnjEruby.connects["exit"] KnjEruby.connects["exit"].each do |block| block.call end end KnjEruby.printcont(tmp_out, args) rescue SystemExit => e KnjEruby.printcont(tmp_out, args) rescue Exception => e begin if KnjEruby.connects["error"] KnjEruby.connects["error"].each do |block| block.call(e) end end rescue SystemExit => e exit rescue Exception => e #An error occurred while trying to run the on-error-block - show this as an normal error. print "\n\n<pre>\n\n" print "<b>#{Knj::Web.html(e.class.name)}: #{Knj::Web.html(e.)}</b>\n\n" #Lets hide all the stuff in what is not the users files to make it easier to debug. bt = e.backtrace #to = bt.length - 9 #bt = bt[0..to] bt.each do |line| print Knj::Web.html(line) + "\n" end print "</pre>" end print "\n\n<pre>\n\n" print "<b>#{Knj::Web.html(e.class.name)}: #{Knj::Web.html(e.)}</b>\n\n" #Lets hide all the stuff in what is not the users files to make it easier to debug. bt = e.backtrace to = bt.length - 9 bt = bt[0..to] bt.each do |line| print Knj::Web.html(line) + "\n" end KnjEruby.printcont(tmp_out, args) end end |
.load_return(filename, args = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/knj/erb/include.rb', line 174 def self.load_return(filename, args = {}) if !args[:io] retio = StringIO.new args[:io] = retio end @args = args KnjEruby.load(filename, args) if !args[:custom_io] retio.rewind return retio.read end end |
.print_headers(args = {}) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/knj/erb/include.rb', line 108 def self.print_headers(args = {}) header_str = "" @headers.each do |header| header_str << "#{header[0]}: #{header[1]}\n" end header_str << "\n" self.reset_headers if @fcgi return header_str end |
.printcont(tmp_out, args = {}) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/knj/erb/include.rb', line 153 def self.printcont(tmp_out, args = {}) if @fcgi @fcgi.print self.print_headers tmp_out.rewind @fcgi.print tmp_out.read.to_s else if args[:io] and !args[:custom_io] old_out = $stdout $stdout = args[:io] elsif !args[:custom_io] $stdout = STDOUT end if !args[:custom_io] print self.print_headers if !args.key?(:with_headers) or args[:with_headers] tmp_out.rewind print tmp_out.read end end end |
.reset_connects ⇒ Object
130 131 132 |
# File 'lib/knj/erb/include.rb', line 130 def self.reset_connects @connects = {} end |
.reset_headers ⇒ Object
134 135 136 137 138 |
# File 'lib/knj/erb/include.rb', line 134 def self.reset_headers @headers = [ ["Content-Type", "text/html; charset=utf-8"] ] end |