Last active
December 14, 2015 06:18
-
-
Save mcfiredrill/5041121 to your computer and use it in GitHub Desktop.
modular sinatra app
taken from here => https://github.com/jfeaver/modular-sinatra/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Datafruits < Sinatra::Base | |
@@my_app = {} | |
def self.new(*) self < Datafruits ? super : Rack::URLMap.new(@@my_app) end | |
def self.map(url) @@my_app[url] = self end | |
# do all config stuff in this file | |
enable :sessions | |
use Rack::Flash | |
class ApplicationController < Datafruits | |
map '/' | |
end | |
class SessionsController < Datafruits | |
map '/' | |
end | |
class UsersController < Datafruits | |
map '/users' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Datafruits | |
class ApplicationController | |
get '/' | |
erb :index | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir = File.expand_path("../", File.dirname(__FILE__)) | |
require "#{dir}/app" | |
app_dir = File.join("#{app_dir}", "app/") | |
controller_files = File.join(app_dir, %w(controllers ** *_controller.rb)) | |
model_files = File.join(app_dir, %w(models ** *.rb)) | |
lib_files = File.join(dir, %w(lib ** *)) | |
files = [controller_files, model_files, lib_files] | |
Dir.glob(files).each {|lf| require lf } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment