Top Level Namespace

Defined Under Namespace

Modules: CodeButler, Enumerable, Kernel, Rack, Sinatra Classes: Array, Class, Fixnum, Hash, NilClass, Proc, String, Symbol

Instance Method Summary collapse

Instance Method Details

#before(&b) ⇒ Object



883
884
885
# File 'lib/codebutler/sinatra.rb', line 883

def before(&b)
  Sinatra.application.define_filter(:before, &b)
end

#configures(*envs, &b) ⇒ Object Also known as: configure



922
923
924
925
926
# File 'lib/codebutler/sinatra.rb', line 922

def configures(*envs, &b)
  yield if  !Sinatra.application.reloading && 
            (envs.include?(Sinatra.application.options.env) ||
            envs.empty?)
end

#delete(path, options = {}, &b) ⇒ Object



879
880
881
# File 'lib/codebutler/sinatra.rb', line 879

def delete(path, options ={}, &b)
  Sinatra.application.define_event(:delete, path, options, &b)
end

#error(type = Sinatra::ServerError, options = {}, &b) ⇒ Object



891
892
893
# File 'lib/codebutler/sinatra.rb', line 891

def error(type = Sinatra::ServerError, options = {}, &b)
  Sinatra.application.define_error(type, options, &b)
end

#get(path, options = {}, &b) ⇒ Object



867
868
869
# File 'lib/codebutler/sinatra.rb', line 867

def get(path, options ={}, &b)
  Sinatra.application.define_event(:get, path, options, &b)
end

#helpers(&b) ⇒ Object



887
888
889
# File 'lib/codebutler/sinatra.rb', line 887

def helpers(&b)
  Sinatra::EventContext.class_eval(&b)
end

#layout(name = :layout, &b) ⇒ Object



899
900
901
# File 'lib/codebutler/sinatra.rb', line 899

def layout(name = :layout, &b)
  Sinatra.application.define_template(name, &b)
end

#mime(ext, type) ⇒ Object



934
935
936
# File 'lib/codebutler/sinatra.rb', line 934

def mime(ext, type)
  Rack::File::MIME_TYPES[ext.to_s] = type
end

#not_found(options = {}, &b) ⇒ Object



895
896
897
# File 'lib/codebutler/sinatra.rb', line 895

def not_found(options = {}, &b)
  Sinatra.application.define_error(Sinatra::NotFound, options, &b)
end

#post(path, options = {}, &b) ⇒ Object



871
872
873
# File 'lib/codebutler/sinatra.rb', line 871

def post(path, options ={}, &b)
  Sinatra.application.define_event(:post, path, options, &b)
end

#put(path, options = {}, &b) ⇒ Object



875
876
877
# File 'lib/codebutler/sinatra.rb', line 875

def put(path, options ={}, &b)
  Sinatra.application.define_event(:put, path, options, &b)
end

#set_options(opts) ⇒ Object



929
930
931
932
# File 'lib/codebutler/sinatra.rb', line 929

def set_options(opts)
  Sinatra::Application.default_options.merge!(opts)
  Sinatra.application.options = nil
end

#template(name, &b) ⇒ Object



903
904
905
# File 'lib/codebutler/sinatra.rb', line 903

def template(name, &b)
  Sinatra.application.define_template(name, &b)
end

#use_in_file_templates!Object



907
908
909
910
911
912
913
914
915
916
917
918
919
920
# File 'lib/codebutler/sinatra.rb', line 907

def use_in_file_templates!
  require 'stringio'
  templates = IO.read(caller.first.split(':').first).split('__FILE__').last
  data = StringIO.new(templates)
  current_template = nil
  data.each do |line|
    if line =~ /^##\s?(.*)/
      current_template = $1.to_sym
      Sinatra.application.templates[current_template] = ''
    elsif current_template
      Sinatra.application.templates[current_template] << line
    end
  end
end