public
Fork of bmizerany/sinatra
Description: Classy web-development dressed in a DSL
Homepage: http://sinatra.rubyforge.org
Clone URL: git://github.com/sr/sinatra.git
in file templates!
sr (author)
Thu Aug 28 13:35:38 -0700 2008
commit  fca8758a492e3767d91f87f8fc172caa15696ade
tree    be21500cdc5c23ae1df941f70662d97b151d9620
parent  f8581c79334164f85c3604b1765c13dab1631034
...
85
86
87
88
 
 
 
89
90
91
92
 
93
94
95
...
466
467
468
469
 
 
470
471
472
...
516
517
518
519
 
520
521
522
523
524
525
 
 
526
527
528
...
766
767
768
769
 
770
771
772
...
814
815
816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
817
818
819
...
904
905
906
907
908
 
...
85
86
87
 
88
89
90
91
92
93
 
94
95
96
97
...
468
469
470
 
471
472
473
474
475
...
519
520
521
 
522
523
524
 
 
 
 
525
526
527
528
529
...
767
768
769
 
770
771
772
773
...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
...
921
922
923
 
924
925
0
@@ -85,11 +85,13 @@ module Sinatra
0
           File.read(path)
0
         end
0
       end
0
-      
0
+
0
+    protected
0
+
0
       def templates
0
         options[:templates] || {}
0
       end
0
-    
0
+
0
   end
0
 
0
 
0
@@ -466,7 +468,8 @@ module Sinatra
0
         :logging => true,
0
         :app_file => $0,
0
         :error_logging => true,
0
-        :raise_errors => false
0
+        :raise_errors => false,
0
+        :templates => {}
0
       }
0
       load_default_options_from_command_line!
0
       @default_options
0
@@ -516,13 +519,11 @@ module Sinatra
0
     end
0
     
0
     def initialize(options = {}, &b)
0
-      @filters     = []
0
+      @filters    = []
0
       @errors     = {}
0
       @middleware = []
0
-      @o          = self.class.default_options.merge(options)
0
-      @options    = OpenStruct.new(@o)
0
-      
0
-      @o[:templates] ||= {}
0
+      @o = self.class.default_options.merge(options)
0
+      @options = OpenStruct.new(@o)
0
 
0
       configure :development do
0
         use EventLogger
0
@@ -766,7 +767,7 @@ module Sinatra
0
       def disable(*opts)
0
         opts.each { |key| set(key, false) }
0
       end
0
-      
0
+
0
       # Determine whether the application is in the process of being
0
       # reloaded.
0
       def reloading?
0
@@ -814,6 +815,22 @@ end
0
 
0
 include Sinatra::DelegatingDSL
0
 
0
+def use_in_file_templates!
0
+  require 'stringio'
0
+  templates = IO.read(caller.first.split(':').first).split('__FILE__').last
0
+  data = StringIO.new(templates)
0
+  current_template = nil
0
+  app = Sinatra.application
0
+  data.each do |line|
0
+    if line =~ /^@@\s?(.*)/
0
+      current_template = $1.to_sym
0
+      app.options.templates[current_template] = ''
0
+    elsif current_template
0
+      app.options.templates[current_template] << line
0
+    end
0
+  end
0
+end
0
+
0
 module Rack
0
 
0
   module Utils
0
@@ -904,4 +921,4 @@ end
0
 at_exit do
0
   exit if $!
0
   Sinatra.application.run
0
-end
0
\ No newline at end of file
0
+end

Comments