Navigation Menu

Skip to content

Commit

Permalink
App init script added.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jul 13, 2013
1 parent fec38c9 commit 03281ae
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 4 deletions.
6 changes: 3 additions & 3 deletions bin/nyara
Expand Up @@ -6,12 +6,12 @@ task_name = args.shift || 'help'


case task_name
when 'help'
Nyara::Command.help
when '-h'
when 'help', '-h'
Nyara::Command.help
when '-v'
Nyara::Command.version
when 'new'
Nyara::Command.new_project(*args)
when 's','server'
Nyara::Command.run_server(*args)
end
5 changes: 5 additions & 0 deletions lib/nyara/command.rb
Expand Up @@ -62,6 +62,11 @@ def new_project(name = nil,*args)

puts "Enjoy!"
end

def run_server(*args)
args ||= []
`ruby config/boot.rb`
end

private
def render_template(fname, opts = {})
Expand Down
4 changes: 3 additions & 1 deletion lib/nyara/templates/Gemfile
@@ -1,4 +1,6 @@
source 'https://rubygems.org'

gem 'nyara', '<%= nyara_version %>'
gem 'tilt'
gem 'erubis'
gem 'nyara', '<%= Nyara::VERSION %>'
gem 'mongoid', '3.1.4'
3 changes: 3 additions & 0 deletions lib/nyara/templates/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
class ApplicationController < Nyara::Controller
set_default_layout 'layouts/application'
end
5 changes: 5 additions & 0 deletions lib/nyara/templates/app/controllers/welcome_controller.rb
@@ -0,0 +1,5 @@
class WelcomeController < ApplicationController
get '/' do
render 'welcome/index'
end
end
10 changes: 10 additions & 0 deletions lib/nyara/templates/app/views/layouts/application.erb
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title><%= app_name %></title>
</head>
<body>
<%%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions lib/nyara/templates/app/views/welcome/index.erb
@@ -0,0 +1 @@
Welcome to use Nyara.
36 changes: 36 additions & 0 deletions lib/nyara/templates/config/boot.rb
@@ -0,0 +1,36 @@
require "nyara"
require "erubis"
require 'bundler' and Bundler.setup(:default)
require 'mongoid'

NYARA_ENV = (ENV['NYARA_ENV'] || 'development').downcase.strip
app_root = File.join(File.dirname(__FILE__),"../")

# load controllers, models
Dir.glob(File.join("app/controllers/**/*")).each do |fname|
require_relative File.join("..",fname)
end
Dir.glob(File.join("app/models/**/*")).each do |fname|
require_relative File.join("..",fname)
end

# Configure Mongoid
Mongoid.load!(File.join(app_root,'config/database.yml'), NYARA_ENV)

configure do
set :env, NYARA_ENV
set :views, 'app/views'
set :session, :name, '_aaa'
set :session, :secure, true
set :session, :expires, 30 * 60

map '/', 'welcome'
end

# TODO: 此处不用会报 Nyara::SimpleController: no action defined (RuntimeError)
get '/' do
send_string ''
end

# require_relative NYARA_ENV

7 changes: 7 additions & 0 deletions lib/nyara/templates/config/development.rb
@@ -0,0 +1,7 @@
configure do
set :port, 3000 # set listening port number
set :workers, 4 # set number of worker process
# if not set, will estimate best n by CPU count

set :logger, true # equivalent to no setting
end
7 changes: 7 additions & 0 deletions lib/nyara/templates/config/production.rb
@@ -0,0 +1,7 @@
configure do
set :port, 3000 # set listening port number
set :workers, 4 # set number of worker process
# if not set, will estimate best n by CPU count

set :logger, true # equivalent to no setting
end
7 changes: 7 additions & 0 deletions lib/nyara/templates/config/test.rb
@@ -0,0 +1,7 @@
configure do
set :port, 3000 # set listening port number
set :workers, 1 # set number of worker process
# if not set, will estimate best n by CPU count

set :logger, true # equivalent to no setting
end

0 comments on commit 03281ae

Please sign in to comment.