dindi 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c956f4624d962f10a0e542ff9db37a3158a269c3
4
+ data.tar.gz: b8360f89f5902eeae21cc10ac3502860a2b9444f
5
+ SHA512:
6
+ metadata.gz: 84a5cd15bc12e9acf41c9999c87e4d9529c08e77c1e741ed7b38ca977af1ca26d956c1cdea1e2cd5dcec8811e8667b51f4445c93fbf7b9a6d3d7b060bc4435c2
7
+ data.tar.gz: 820740421268764012a53355ccd6592c7b98afa0e87b92c97ce89ee21a059a732305993701ad91eeeec481916dc97bdc0ebdfd006d58686b9b966b558a0af63e
data/Gemfile CHANGED
@@ -3,13 +3,11 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "colorize"
6
- gem "bundler", ">= 1.0.0"
6
+ gem "bundler"
7
7
 
8
8
  # Add dependencies to develop your gem here.
9
9
  # Include everything needed to run rake, tests, features, etc.
10
10
  group :development do
11
- gem "shoulda", ">= 0"
12
- gem "bundler", ">= 1.0.0"
13
- gem "jeweler", "~> 1.6.4"
14
- gem "simplecov", ">= 0"
11
+ gem "bundler"
12
+ gem "jeweler"
15
13
  end
data/Gemfile.lock CHANGED
@@ -1,41 +1,57 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.2.13)
5
- i18n (= 0.6.1)
6
- multi_json (~> 1.0)
7
- bourne (1.4.0)
8
- mocha (~> 0.13.2)
9
- colorize (0.5.8)
10
- git (1.2.5)
11
- i18n (0.6.1)
12
- jeweler (1.6.4)
13
- bundler (~> 1.0)
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ colorize (0.7.3)
7
+ descendants_tracker (0.0.4)
8
+ thread_safe (~> 0.3, >= 0.3.1)
9
+ faraday (0.9.0)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.2.7)
12
+ github_api (0.11.3)
13
+ addressable (~> 2.3)
14
+ descendants_tracker (~> 0.0.1)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 1.2)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ nokogiri (~> 1.6.0)
19
+ oauth2
20
+ hashie (3.1.0)
21
+ highline (1.6.21)
22
+ jeweler (2.0.1)
23
+ builder
24
+ bundler (>= 1.0)
14
25
  git (>= 1.2.5)
26
+ github_api
27
+ highline (>= 1.6.15)
28
+ nokogiri (>= 1.5.10)
15
29
  rake
16
- metaclass (0.0.1)
17
- mocha (0.13.3)
18
- metaclass (~> 0.0.1)
19
- multi_json (1.7.2)
20
- rake (10.0.4)
21
- shoulda (3.4.0)
22
- shoulda-context (~> 1.0, >= 1.0.1)
23
- shoulda-matchers (~> 1.0, >= 1.4.1)
24
- shoulda-context (1.1.1)
25
- shoulda-matchers (1.5.6)
26
- activesupport (>= 3.0.0)
27
- bourne (~> 1.3)
28
- simplecov (0.7.1)
29
- multi_json (~> 1.0)
30
- simplecov-html (~> 0.7.1)
31
- simplecov-html (0.7.1)
30
+ rdoc
31
+ json (1.8.1)
32
+ jwt (1.0.0)
33
+ mini_portile (0.6.0)
34
+ multi_json (1.10.1)
35
+ multi_xml (0.5.5)
36
+ multipart-post (2.0.0)
37
+ nokogiri (1.6.2.1)
38
+ mini_portile (= 0.6.0)
39
+ oauth2 (0.9.4)
40
+ faraday (>= 0.8, < 0.10)
41
+ jwt (~> 1.0)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (~> 1.2)
45
+ rack (1.5.2)
46
+ rake (10.3.2)
47
+ rdoc (4.1.1)
48
+ json (~> 1.4)
49
+ thread_safe (0.3.4)
32
50
 
33
51
  PLATFORMS
34
52
  ruby
35
53
 
36
54
  DEPENDENCIES
37
- bundler (>= 1.0.0)
55
+ bundler
38
56
  colorize
39
- jeweler (~> 1.6.4)
40
- shoulda
41
- simplecov
57
+ jeweler
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "dindi"
18
18
  gem.homepage = "http://github.com/samchandra/dindi"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{Dindi is a hit of Sinatra}
20
+ gem.summary = %Q{Dindi is a hit from Sinatra}
21
21
  gem.description = %Q{This gem will create a modular base for a new Sinatra app}
22
22
  gem.email = "samuelchandra@yahoo.com"
23
23
  gem.authors = ["Samuel Chandra"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
@@ -8,7 +8,9 @@ module Dindi
8
8
  module CommandParser
9
9
 
10
10
  def self.parse(args, options)
11
- # The options specified on the command line will be collected in *options*.
11
+ # The options specified on the command line will be collected in
12
+ # *options*.
13
+ #
12
14
  # We set the default value here
13
15
  options.project_name = nil
14
16
 
@@ -20,12 +22,7 @@ module Dindi
20
22
 
21
23
  opts.on("-n", "--name PROJECT_NAME",
22
24
  "Specify your project name PROJECT_NAME that will be created") do |lib|
23
- options.project_name = lib
24
- end
25
-
26
- opts.on("-r", "--ruby RUBY_VERSION",
27
- "Set RUBY_VERSION to 1.9.1 for compatibility mode") do |ver|
28
- options.ruby_version = ver
25
+ options.project_name = lib.downcase
29
26
  end
30
27
 
31
28
  # No argument, shows at tail. This will print an options summary.
@@ -40,17 +37,12 @@ module Dindi
40
37
 
41
38
  opts.parse!(args)
42
39
 
43
- if options.ruby_version.nil? or options.ruby_version.gsub(".", "").to_i > 191
44
- options.ruby_version = "1.9.2"
45
- else
46
- options.ruby_version = "1.9.1"
47
- end
40
+ options.ruby_version = "latest"
48
41
 
49
- # set project absolute dir early
50
- options.project_absolute_dir = if options.project_name
51
- FileUtils.pwd + "/" + options.project_name
52
- else
53
- nil
42
+ # set project absolute dir
43
+ options.project_absolute_dir = nil
44
+ if options.project_name
45
+ options.project_absolute_dir = File.join(FileUtils.pwd, options.project_name)
54
46
  end
55
47
 
56
48
  rescue Exception => e
@@ -7,8 +7,8 @@ module Dindi
7
7
 
8
8
  def self.create_default_directories(options)
9
9
  project_absolute_dir = options.project_absolute_dir
10
- %w(tmp log public push views routes extlibs models helpers).each do |dir|
11
- FileUtils.mkdir_p(project_absolute_dir + "/" + dir)
10
+ %w(tmp log public push views routes extlibs models helpers tests scripts).each do |dir|
11
+ FileUtils.mkdir_p(File.join(project_absolute_dir, dir))
12
12
  end
13
13
  end
14
14
 
@@ -19,8 +19,8 @@ module Dindi
19
19
  # version specific file templates and shared template together
20
20
  [ruby_version, "shared"].each do |dir_name|
21
21
 
22
- Dir.glob(File.dirname(__FILE__) + "/file_templates/#{dir_name}/*").each do |file|
23
- filename = file.split("/").last.gsub(".erb", "")
22
+ Dir.glob(File.join(File.dirname(__FILE__), 'file_templates', dir_name, '*')).each do |file|
23
+ filename = File.basename(file, ".*")
24
24
 
25
25
  # read file as ERB templates
26
26
  content = File.open(file, "r").read
@@ -45,15 +45,16 @@ module Dindi
45
45
  project_absolute_dir = options.project_absolute_dir
46
46
 
47
47
  # copy location for not common template files
48
- special_location_hash = {"helpers.rb" => "#{project_absolute_dir}/helpers/helpers.rb",
49
- "docs.haml" => "#{project_absolute_dir}/views/docs.haml",
50
- "project_name.rb" => "#{project_absolute_dir}/#{options.project_name}.rb"
48
+ special_location_hash = {"debug_on.rb" => File.join(project_absolute_dir, 'helpers', 'debug_on.rb'),
49
+ "deploy_setting.rb" => File.join(project_absolute_dir, 'helpers', 'deploy_setting.rb'),
50
+ "docs.haml" => File.join(project_absolute_dir, 'views', 'docs.haml'),
51
+ "project_name.rb" => File.join(project_absolute_dir, "#{options.project_name}.rb")
51
52
  }
52
53
 
53
54
  if special_location_hash[filename]
54
55
  return special_location_hash[filename]
55
56
  else
56
- return "#{project_absolute_dir}/#{filename}"
57
+ return File.join(project_absolute_dir, filename)
57
58
  end
58
59
 
59
60
  end
@@ -7,4 +7,5 @@ gem "activesupport"
7
7
  gem "activerecord"
8
8
  gem "json"
9
9
  gem "pony"
10
- gem "thin"
10
+
11
+ gem "rest-client"
@@ -0,0 +1,47 @@
1
+ $: << "."
2
+
3
+ # we use bundler
4
+ require 'bundler/setup'
5
+
6
+ # modular sinatra app
7
+ require 'sinatra/base'
8
+
9
+ # gems
10
+ %w(logger json haml digest date time pony).each {|gem| require gem}
11
+
12
+ # helpers
13
+ Dir.glob("./helpers/*.rb").each {|helper| require helper}
14
+
15
+ # load db config and models
16
+ require 'models'
17
+
18
+ # extra library
19
+ Dir.glob("./extlibs/*.rb").each {|extlib| require extlib}
20
+
21
+ # controllers
22
+ Dir.glob("./routes/*.rb").each {|route| require route}
23
+
24
+ # app file
25
+ require '<%= options.project_name %>'
26
+
27
+ class Sinatra::Base
28
+ # helpers
29
+ include DebugOn
30
+
31
+ # set sinatra's variables
32
+ set :app_name, "<%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %>"
33
+ set :app_logger, ::Logger.new(File.join(File.dirname(__FILE__), 'log', "<%= options.project_name %>.log"))
34
+ set :root, File.dirname(__FILE__)
35
+ set :environment, DeploySetting.environment
36
+
37
+ if settings.environment == :production
38
+ enable :sessions, :logging, :dump_errors
39
+ disable :run, :reload, :show_exceptions
40
+ else
41
+ enable :sessions, :logging, :dump_errors, :show_exceptions
42
+ disable :run, :reload
43
+ end
44
+
45
+ end
46
+
47
+ run <%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %>
@@ -0,0 +1,19 @@
1
+ production:
2
+ adapter: mysql2
3
+ username: root
4
+ password: password
5
+ host: localhost
6
+ timezone: SGT
7
+ reconnect: true
8
+ database: <%= options.project_name %>
9
+ encoding: utf8
10
+
11
+ development:
12
+ adapter: mysql2
13
+ username: root
14
+ password: password
15
+ host: localhost
16
+ timezone: SGT
17
+ reconnect: true
18
+ database: <%= options.project_name %>_dev
19
+ encoding: utf8
@@ -0,0 +1,14 @@
1
+ require 'mysql2'
2
+ require 'active_record'
3
+
4
+ config = YAML.load_file(File.join(File.dirname(__FILE__), 'database.yml'))
5
+
6
+ if DeploySetting.environment == :production
7
+ ActiveRecord::Base.establish_connection(config["production"])
8
+ else
9
+ ActiveRecord::Base.establish_connection(config["development"])
10
+ end
11
+
12
+ ActiveRecord::Base.include_root_in_json = false
13
+
14
+ Dir.glob(File.join(File.dirname(__FILE__), "models", "*.rb")).each {|model| require model}
@@ -0,0 +1,29 @@
1
+ module DebugOn
2
+
3
+ def app_debug_on
4
+ settings.app_logger.info("===== START =====> #{Time.now.strftime("%d/%m/%Y %H:%M %p")}")
5
+ settings.app_logger.info(request.url)
6
+ settings.app_logger.info("Params:")
7
+ params.each do |key, value|
8
+ settings.app_logger.info("#{key} => #{value}")
9
+ end
10
+ end
11
+
12
+ def app_logger(text)
13
+ settings.app_logger.info(text)
14
+ end
15
+
16
+ # Basic Authentication
17
+ def protected!
18
+ unless authorized?
19
+ response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
20
+ throw(:halt, [401, "Not authorized\n"])
21
+ end
22
+ end
23
+
24
+ def authorized?
25
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
26
+ @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'password']
27
+ end
28
+
29
+ end
@@ -0,0 +1,9 @@
1
+ class DeploySetting
2
+
3
+ class << self
4
+ def environment
5
+ :development
6
+ end
7
+ end
8
+
9
+ end
@@ -1,6 +1,6 @@
1
1
  %html
2
2
  %head
3
- %title= if @page_title then "CMS " + @page_title.humanize else "CMS" end
3
+ %title Docs
4
4
  %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
5
5
  %meta{:content => "NONE,NOARCHIVE", :name => "robots"}
6
6
  %link{:href => "http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css", :rel => "stylesheet", :type => "text/css"}
@@ -25,7 +25,7 @@
25
25
  %th{:width => "45%"} Description
26
26
  %tfoot
27
27
  %tr
28
- %td{:colspan => "3"} Copyright &copy;2013
28
+ %td{:colspan => "3"} Copyright &copy;2014
29
29
  %tbody
30
30
  %tr
31
31
  %td GET
@@ -1,5 +1,8 @@
1
1
  class <%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %> < Sinatra::Base
2
2
 
3
+ # Routes
4
+ # use Cms
5
+
3
6
  # index
4
7
  get '/' do
5
8
  '<%= options.project_name %>'
@@ -8,7 +11,6 @@ class <%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %> < Sinatra::Ba
8
11
  # docs
9
12
  get '/docs' do
10
13
  protected!
11
- @page_title = "Docs"
12
14
  haml :docs, :layout => false
13
15
  end
14
16
 
metadata CHANGED
@@ -1,110 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dindi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Samuel Chandra
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-16 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: colorize
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: 1.0.0
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: 1.0.0
46
- - !ruby/object:Gem::Dependency
47
- name: shoulda
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
31
+ - - '>='
52
32
  - !ruby/object:Gem::Version
53
33
  version: '0'
54
- type: :development
34
+ type: :runtime
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
- - - ! '>='
38
+ - - '>='
60
39
  - !ruby/object:Gem::Version
61
40
  version: '0'
62
41
  - !ruby/object:Gem::Dependency
63
42
  name: bundler
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - ! '>='
45
+ - - '>='
68
46
  - !ruby/object:Gem::Version
69
- version: 1.0.0
47
+ version: '0'
70
48
  type: :development
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - ! '>='
52
+ - - '>='
76
53
  - !ruby/object:Gem::Version
77
- version: 1.0.0
54
+ version: '0'
78
55
  - !ruby/object:Gem::Dependency
79
56
  name: jeweler
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ~>
84
- - !ruby/object:Gem::Version
85
- version: 1.6.4
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: 1.6.4
94
- - !ruby/object:Gem::Dependency
95
- name: simplecov
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
58
  requirements:
99
- - - ! '>='
59
+ - - '>='
100
60
  - !ruby/object:Gem::Version
101
61
  version: '0'
102
62
  type: :development
103
63
  prerelease: false
104
64
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
65
  requirements:
107
- - - ! '>='
66
+ - - '>='
108
67
  - !ruby/object:Gem::Version
109
68
  version: '0'
110
69
  description: This gem will create a modular base for a new Sinatra app
@@ -126,45 +85,38 @@ files:
126
85
  - lib/dindi.rb
127
86
  - lib/dindi/command_parser.rb
128
87
  - lib/dindi/file_helper.rb
129
- - lib/dindi/file_templates/1.9.1/Gemfile.erb
130
- - lib/dindi/file_templates/1.9.1/config.ru.erb
131
- - lib/dindi/file_templates/1.9.1/database.yml.erb
132
- - lib/dindi/file_templates/1.9.1/models.rb.erb
133
- - lib/dindi/file_templates/1.9.2/Gemfile.erb
134
- - lib/dindi/file_templates/1.9.2/config.ru.erb
135
- - lib/dindi/file_templates/1.9.2/database.yml.erb
136
- - lib/dindi/file_templates/1.9.2/models.rb.erb
88
+ - lib/dindi/file_templates/latest/Gemfile.erb
89
+ - lib/dindi/file_templates/latest/config.ru.erb
90
+ - lib/dindi/file_templates/latest/database.yml.erb
91
+ - lib/dindi/file_templates/latest/models.rb.erb
92
+ - lib/dindi/file_templates/shared/debug_on.rb.erb
93
+ - lib/dindi/file_templates/shared/deploy_setting.rb.erb
137
94
  - lib/dindi/file_templates/shared/docs.haml.erb
138
- - lib/dindi/file_templates/shared/helpers.rb.erb
139
95
  - lib/dindi/file_templates/shared/project_name.rb.erb
140
96
  - test/helper.rb
141
97
  - test/test_dindi.rb
142
98
  homepage: http://github.com/samchandra/dindi
143
99
  licenses:
144
100
  - MIT
101
+ metadata: {}
145
102
  post_install_message:
146
103
  rdoc_options: []
147
104
  require_paths:
148
105
  - lib
149
106
  required_ruby_version: !ruby/object:Gem::Requirement
150
- none: false
151
107
  requirements:
152
- - - ! '>='
108
+ - - '>='
153
109
  - !ruby/object:Gem::Version
154
110
  version: '0'
155
- segments:
156
- - 0
157
- hash: 4037155346142818555
158
111
  required_rubygems_version: !ruby/object:Gem::Requirement
159
- none: false
160
112
  requirements:
161
- - - ! '>='
113
+ - - '>='
162
114
  - !ruby/object:Gem::Version
163
115
  version: '0'
164
116
  requirements: []
165
117
  rubyforge_project:
166
- rubygems_version: 1.8.23
118
+ rubygems_version: 2.0.3
167
119
  signing_key:
168
- specification_version: 3
169
- summary: Dindi is a hit of Sinatra
120
+ specification_version: 4
121
+ summary: Dindi is a hit from Sinatra
170
122
  test_files: []
@@ -1,11 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem "rack", "1.2.2"
4
- gem "sinatra", "1.2.6"
5
- gem "haml", "3.0.13"
6
- gem "activesupport", "~> 3.0.9"
7
- gem "activerecord", "~> 3.0.9"
8
- gem "mysql2", "~> 0.2.7"
9
- gem "json"
10
- gem "pony"
11
- gem "thin"
@@ -1,53 +0,0 @@
1
- $: << "."
2
-
3
- # we use bundler
4
- require 'bundler/setup'
5
-
6
- # modular sinatra app
7
- require 'sinatra/base'
8
-
9
- # gems
10
- %w(logger json haml csv digest date time activesupport pony).each {|lib| require lib}
11
-
12
- # load db config and models
13
- require 'models'
14
-
15
- # extra library
16
- Dir.glob("./extlibs/*.rb").each {|extlib| require extlib}
17
-
18
- # helpers
19
- Dir.glob("./helpers/*.rb").each {|helper| require helper}
20
-
21
- # controllers
22
- Dir.glob("./routes/*.rb").each {|route| require route}
23
-
24
- # app file
25
- require '<%= options.project_name %>'
26
-
27
- # custom app logger different from sinatra logging
28
- $APP_LOG = ::Logger.new("log/<%= options.project_name %>.log")
29
-
30
- # app name
31
- $APP_NAME = "<%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %>"
32
-
33
- class Sinatra::Base
34
- # helpers
35
- include DebugOn
36
-
37
- # set sinatra's variables
38
- set :root, ::File.dirname(__FILE__)
39
- set :environment, :production
40
- enable :sessions, :logging, :dump_errors, :show_exceptions
41
- disable :run, :reload
42
- end
43
-
44
- # app routes
45
- App = Rack::Builder.app do
46
- # routes
47
- # use Cms
48
-
49
- run <%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %>
50
- end
51
-
52
- # finally
53
- run App
@@ -1,9 +0,0 @@
1
- production:
2
- adapter: mysql2
3
- username: root
4
- password: password
5
- host: localhost
6
- timezone: SGT
7
- reconnect: true
8
- database: <%= options.project_name %>
9
- encoding: utf8
@@ -1,8 +0,0 @@
1
- require 'mysql2'
2
- require 'activerecord'
3
-
4
- config = YAML.load_file('database.yml')
5
- ActiveRecord::Base.establish_connection(config["production"])
6
- ActiveRecord::Base.include_root_in_json = false
7
-
8
- Dir.glob("<%= project_absolute_dir %>/models/*.rb").each {|model| require model}
@@ -1,53 +0,0 @@
1
- $: << "."
2
-
3
- # we use bundler
4
- require 'bundler/setup'
5
-
6
- # modular sinatra app
7
- require 'sinatra/base'
8
-
9
- # gems
10
- %w(logger json haml csv digest date time active_support pony).each {|lib| require lib}
11
-
12
- # load db config and models
13
- require 'models'
14
-
15
- # extra library
16
- Dir.glob("./extlibs/*.rb").each {|extlib| require extlib}
17
-
18
- # helpers
19
- Dir.glob("./helpers/*.rb").each {|helper| require helper}
20
-
21
- # controllers
22
- Dir.glob("./routes/*.rb").each {|route| require route}
23
-
24
- # app file
25
- require '<%= options.project_name %>'
26
-
27
- # custom app logger different from sintra logging
28
- $APP_LOG = ::Logger.new("log/<%= options.project_name %>.log")
29
-
30
- # app name
31
- $APP_NAME = "<%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %>"
32
-
33
- class Sinatra::Base
34
- # helpers
35
- include DebugOn
36
-
37
- # set sinatra's variables
38
- set :root, File.dirname(__FILE__)
39
- set :environment, :production
40
- enable :sessions, :logging, :dump_errors, :show_exceptions
41
- disable :run, :reload
42
- end
43
-
44
- # app routes
45
- App = Rack::Builder.app do
46
- # routes
47
- # use Cms
48
-
49
- run <%= options.project_name.gsub(/(?:^|_)(.)/) { $1.upcase } %>
50
- end
51
-
52
- # finally
53
- run App
@@ -1,9 +0,0 @@
1
- production:
2
- adapter: mysql2
3
- username: root
4
- password: password
5
- host: localhost
6
- timezone: SGT
7
- reconnect: true
8
- database: <%= options.project_name %>
9
- encoding: utf8
@@ -1,8 +0,0 @@
1
- require 'mysql2'
2
- require 'active_record'
3
-
4
- config = YAML.load_file('database.yml')
5
- ActiveRecord::Base.establish_connection(config["production"])
6
- ActiveRecord::Base.include_root_in_json = false
7
-
8
- Dir.glob("<%= project_absolute_dir %>/models/*.rb").each {|model| require model}
@@ -1,38 +0,0 @@
1
- module DebugOn
2
-
3
- def debug_on
4
- logger.info("===== START =====> #{Time.now.strftime("%d/%m/%Y %H:%M %p")}")
5
- logger.info(request.url)
6
- logger.info("Params:")
7
- params.each do |key, value|
8
- logger.info("#{key} => #{value}")
9
- end
10
- end
11
-
12
- def app_debug_on
13
- $APP_LOG.info("===== START =====> #{Time.now.strftime("%d/%m/%Y %H:%M %p")}")
14
- $APP_LOG.info(request.url)
15
- $APP_LOG.info("Params:")
16
- params.each do |key, value|
17
- $APP_LOG.info("#{key} => #{value}")
18
- end
19
- end
20
-
21
- def app_logger(text)
22
- $APP_LOG.info(text)
23
- end
24
-
25
- # Basic Authentication
26
- def protected!
27
- unless authorized?
28
- response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
29
- throw(:halt, [401, "Not authorized\n"])
30
- end
31
- end
32
-
33
- def authorized?
34
- @auth ||= Rack::Auth::Basic::Request.new(request.env)
35
- @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'dindidocs']
36
- end
37
-
38
- end