Last active
June 30, 2016 14:14
-
-
Save u007/60c01a4712296c1e0697967189b670e1 to your computer and use it in GitHub Desktop.
padrino view working!
This file contains hidden or 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
using slim layout | |
tested both erb and slim view file, same issue | |
RACK_ENV=james | |
This file contains hidden or 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
module MyApp | |
class App < Padrino::Application | |
use ConnectionPoolManagement | |
set :login_model, :user_access | |
register Padrino::Mailer | |
register Padrino::Helpers | |
register Padrino::Sprockets | |
# register Padrino::Cache | |
# register I18n::JS::Middleware | |
# register Padrino::Login | |
register Padrino::Access | |
register PaperTrail::Sinatra | |
# enable :session | |
# https://github.com/padrino/padrino-auth/blob/12e4fd8f3cdaae1f82353f00f0d055977d8711c5/lib/padrino-auth/access.rb | |
set_access :*, :allow => :index | |
helpers do | |
# Auth access - called from padrino::access | |
def credentials | |
# puts "restoring permission" | |
# puts settings.permissions.inspect | |
@login ||= false | |
if session[:current_user_id] && session[:current_user_id].to_i > 0 | |
@login ||= UserAccess.authenticate(:id => session[:current_user_id]) | |
if @login == false | |
session[:current_user_id] = 0 # user no longer exists | |
end | |
end | |
@login | |
end | |
def credentials=(user) | |
@login = user | |
session[:current_user_id] = @login ? @login.id : nil | |
end | |
def authorized? | |
true | |
end | |
def authorized2? | |
allowed = ['/restricted', '/api/update', '/login', '/'].include?(request.env['PATH_INFO']) | |
if allowed | |
return true | |
end | |
# allow any logged in user | |
!current_user.nil? | |
end | |
# def authorized? | |
# | |
# if current_user.nil? | |
# !restricted | |
# else | |
# # todo check role | |
# binding.pry | |
# true | |
# end | |
# end | |
end | |
if Padrino.env == :production | |
sprockets minify: true | |
disable :reload | |
disable :reload_templates | |
else | |
sprockets minify: false | |
enable :reload | |
enable :reload_templates | |
end | |
# enable :caching | |
# | |
# You can customize caching store engines: | |
# | |
# set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory | |
# set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost | |
# set :cache, Padrino::Cache.new(:Memcached, :server => '127.0.0.1:11211', :exception_retry_limit => 1) | |
# set :cache, Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance) | |
# set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost | |
# set :cache, Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0) | |
# set :cache, Padrino::Cache.new(:Redis, :backend => redis_instance) | |
# set :cache, Padrino::Cache.new(:Mongo) # Uses default server at localhost | |
# set :cache, Padrino::Cache.new(:Mongo, :backend => mongo_client_instance) | |
# set :cache, Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice | |
# | |
## | |
# Application configuration options. | |
# | |
# set :raise_errors, true # Raise exceptions (will stop application) (default for test) | |
# set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development) | |
# set :show_exceptions, true # Shows a stack trace in browser (default for development) | |
# set :logging, true # Logging in STDOUT for development and file for production (default only for development) | |
# set :public_folder, 'foo/bar' # Location for static assets (default root/public) | |
# set :reload, false # Reload application files (default in development) | |
# set :default_builder, 'foo' # Set a custom form builder (default 'StandardFormBuilder') | |
# set :locale_path, 'bar' # Set path for I18n translations (default your_apps_root_path/locale) | |
# disable :sessions # Disabled sessions by default (enable if needed) | |
# disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined) | |
# layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application) | |
# | |
get "/restricted" do | |
"Unauthorized access" | |
end | |
# You can manage errors like: | |
# | |
# error 404 do | |
# render 'errors/404' | |
# end | |
# | |
# error 500 do | |
# render 'errors/500' | |
# end | |
# | |
end | |
end |
This file contains hidden or 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
MyApp::App.controllers :pages, map: "/p/" do | |
layout :admin | |
get :index, provides: [:html] do | |
render 'pages/index' # pages/index.slim | |
end | |
get :erb do | |
render 'pages/erb' # pages/erb.erb | |
end | |
end |
This file contains hidden or 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
<doctype html> | |
<html> | |
<head> | |
<title>test</title> | |
</head> | |
<body> | |
<%= yield %> | |
</body> | |
</html> |
This file contains hidden or 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
Padrino.mount('Myapp::App', :app_file => Padrino.root('app/app.rb')).to('/') |
This file contains hidden or 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
# Defines our constants | |
RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV) | |
PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT) | |
# Load our dependencies | |
require 'bundler/setup' | |
Bundler.require(:default, RACK_ENV) | |
I18n.default_locale = :en | |
Padrino.configure :development do |config| | |
Padrino::Logger::Config[:development] = { :log_level => :devel, :stream => :stdout, :format_datetime => '' } | |
Padrino.configure_apps do | |
set :site_domain, '127.0.0.1' | |
end | |
end | |
Padrino.configure :james do |config| | |
# Padrino::Logger::Config[:development][:log_static] = true | |
Padrino::Logger::Config[:james] = { :log_level => :devel, :stream => :stdout, :format_datetime => '' } | |
Padrino.configure_apps do | |
set :app_domain, '127.0.0.1' | |
end | |
end | |
Padrino.configure :production do |config| | |
# Padrino::Logger::Config[:development][:log_static] = true | |
# Padrino::Logger::Config[:james] = { :log_level => :devel, :stream => :stdout, :format_datetime => '' } | |
Padrino.configure_apps do | |
set :app_domain, 'myapp.domain.com' | |
end | |
end | |
# for store models | |
module Store | |
end | |
## | |
# Require initializers before all other dependencies. | |
# Dependencies from 'config' folder are NOT re-required on reload. | |
# | |
Padrino.dependency_paths.unshift Padrino.root('config/initializers/*.rb') | |
# insert after lib/**/*.rb | |
Padrino.dependency_paths.insert(3, | |
Padrino.root('app/uploaders/*.rb'), ) | |
# puts "dependencies: #{Padrino.dependency_paths.inspect}" | |
## | |
# Add your before (RE)load hooks here | |
# These hooks are run before any dependencies are required. | |
# | |
Padrino.before_load do | |
I18n::JS.export if Padrino.env == :development || Padrino.env==:james | |
# I18n.locale = :de | |
Padrino.dependency_paths << Padrino.root('lib/activerecord/*.rb') | |
# puts "before load dependencies: #{Padrino.dependency_paths.inspect}" | |
end | |
## | |
# Add your after (RE)load hooks here | |
# | |
Padrino.load! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment