sinatraband 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c20947b192c26da1bc25aa1e14d9dea567dc0714
4
- data.tar.gz: fd9aa123d7469a41eb00ef323f21840d0cbb2b6e
3
+ metadata.gz: f283e45cf27dfbd3f042bc006c8d15ea563da070
4
+ data.tar.gz: 8a2ccd92153ccd08cae03c6cfdb22d5aa6ef210b
5
5
  SHA512:
6
- metadata.gz: b6fc6031ded1caa7e13797e020c9eb2cc58165f30e5797a3165de6acd73b52643d5ddc2702d149b3551616844b57aa3a6921e249c06db12b76f55106e5593fc5
7
- data.tar.gz: d822e781c11dfaebf7dd440f2f573841cd4b7f2afac1fe04885a229e9d31e38d7165164fd7288f9027999f33ab4814da58e260af476842df85b4bd3303d72670
6
+ metadata.gz: c751fbb881ed97f18b0da6824daa533ffdd44952499149544ab7a99fd313e8c6f7690a1582ef4e7ad3c01974f0258806575a39b23558b389a6a818b258540644
7
+ data.tar.gz: a589f3d9c70fc421be7140e773f66f9ce0a970ddaef7aec3cda5d44f7e4d2c7d88a87381702ba84f114c397e60231a5fc51beb59cf38a11a4d516b959ab50851
data/bin/app.rb CHANGED
@@ -47,6 +47,9 @@ class App
47
47
  #Creates the App diretory
48
48
  mkdir directory: "./#{@name}"
49
49
 
50
+ #Creates the Config diretory
51
+ mkdir directory: "./#{@name}/config"
52
+
50
53
  #Creates the Models diretory
51
54
  mkdir directory: "./#{@name}/models"
52
55
 
@@ -69,11 +72,17 @@ class App
69
72
  #Creates the App file
70
73
  generate_file_from_template directory: "", template: "app", final_file: "app", extension: ".rb"
71
74
 
72
- #Creates the Database file
73
- generate_file_from_template directory: "/db", template: "connection", final_file: "connection", extension: ".rb"
75
+ #Creates the Config file
76
+ generate_file_from_template directory: "/config", template: "config", final_file: "config", extension: ".rb"
77
+
78
+ #Creates the layout file
79
+ generate_file_from_template directory: "/views", template: "layout", final_file: "layout", extension: ".erb"
74
80
 
75
81
  #Creates the index file
76
82
  generate_file_from_template directory: "/views", template: "index", final_file: "index", extension: ".erb"
83
+
84
+ #Creates the error file
85
+ generate_file_from_template directory: "/views", template: "error", final_file: "error", extension: ".erb"
77
86
  end
78
87
 
79
88
  def create_model input={model_name: '', model_properties: {}}
@@ -94,7 +103,7 @@ class App
94
103
  generate_file_from_template directory: "/db/migrate", template: "migration", final_file: "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_#{input[:model_name].downcase}", extension: ".rb"
95
104
 
96
105
  #Creates the View diretory
97
- mkdir directory: ".#{@name}/views/#{input[:model_name].downcase.pluralize}"
106
+ mkdir directory: "./#{@name}/views/#{input[:model_name].downcase.pluralize}"
98
107
  end
99
108
 
100
109
  end
data/bin/helper.rb CHANGED
@@ -8,18 +8,18 @@ def generate_file_from_template input={directory: "./#{@name}", template: '', fi
8
8
  end
9
9
 
10
10
  File.open(file_name, 'w') do |f|
11
- begin
12
- file_template = ERB.new(File.open("#{@root}#{input[:directory]}/#{input[:template]}.erb").read)
13
- rescue (Errno::ENOENT)
14
- put_error_and_quit "Error: Missing template for file #{@root}#{input[:directory]}/#{input[:template]}#{input[:extension]}."
15
- end
16
-
17
- begin
18
- f.write(file_template.result(binding))
19
- puts ".#{input[:directory]}/#{input[:final_file]}#{input[:extension]} file created."
20
- rescue (Errno::ENOENT)
21
- put_error_and_quit "Error creating #{input[:final_file]}#{input[:extension]}."
22
- end
11
+ begin
12
+ file_template = ERB.new(File.open("#{@root}#{input[:directory]}/#{input[:template]}.erb").read)
13
+ rescue (Errno::ENOENT)
14
+ put_error_and_quit "Error: Missing template for file #{@root}#{input[:directory]}/#{input[:template]}#{input[:extension]}."
15
+ end
16
+
17
+ begin
18
+ f.write(file_template.result(binding))
19
+ puts ".#{input[:directory]}/#{input[:final_file]}#{input[:extension]} file created."
20
+ rescue (Errno::ENOENT)
21
+ put_error_and_quit "Error creating #{input[:final_file]}#{input[:extension]}."
22
+ end
23
23
  end
24
24
  end
25
25
 
@@ -2,6 +2,20 @@
2
2
  source "https://rubygems.org"
3
3
 
4
4
  gem "mysql2"
5
+ gem "puma"
5
6
  gem "rake"
6
7
  gem "sinatra-activerecord"
7
- # gem "bcrypt-ruby"
8
+
9
+ # gem "sinatra-flash"
10
+ # gem "bcrypt-ruby"
11
+
12
+ # group :production do
13
+ # gem "pg"
14
+ # end
15
+
16
+ # group :test do
17
+ # gem "simplecov"
18
+ # gem "rspec"
19
+ # end
20
+
21
+ # ruby "2.0.0"
@@ -1,11 +1,10 @@
1
1
  require 'sinatra'
2
+ require 'sinatra/activerecord'
3
+ # require 'active_support/core_ext'
4
+ # require 'sinatra/flash'
2
5
 
3
- # Loads database configuration
4
- require_relative './db/connection.rb'
5
-
6
- # Enables session
7
- enable :sessions
8
- set :session_secret, 'your secret key'
6
+ # Loads app config
7
+ require_relative './config/config.rb'
9
8
 
10
9
  # Loads all models in models directory
11
10
  Dir["./models/*.rb"].each {|file| require_relative file }
@@ -16,4 +15,14 @@ Dir["./controllers/*.rb"].each {|file| require_relative file }
16
15
  # Default root_route
17
16
  get '/' do
18
17
  erb :'index'
18
+ end
19
+
20
+ # Default Not found page
21
+ not_found do
22
+ erb :'error'
23
+ end
24
+
25
+ # Default Error page
26
+ error do
27
+ erb :'error'
19
28
  end
@@ -0,0 +1,36 @@
1
+ # Adds gzip compression to requests
2
+ use Rack::Deflater
3
+
4
+ # Register Flash Sinatra messages
5
+ # register Sinatra::Flash
6
+
7
+ # Configs timezone
8
+ ActiveRecord::Base.default_timezone = :local
9
+
10
+ # Enables session
11
+ enable :sessions
12
+ set :session_secret, 'your secret key'
13
+ # use Rack::Session::Pool, :secret => 'your secret key'
14
+
15
+ # Loads database configuration
16
+ set :database, "mysql2://root:@localhost/<%= @name %>"
17
+
18
+ # configure :production do
19
+ # db = URI.parse(ENV['DATABASE_URL'] || 'postgres:///localhost/<%= @name %>')
20
+
21
+ # ActiveRecord::Base.establish_connection(
22
+ # :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
23
+ # :host => db.host,
24
+ # :username => db.user,
25
+ # :password => db.password,
26
+ # :database => db.path[1..-1],
27
+ # :encoding => 'utf8'
28
+ # )
29
+ # end
30
+
31
+ # html escape method
32
+ # helpers do
33
+ # def h(text)
34
+ # Rack::Utils.escape_html(text)
35
+ # end
36
+ # end
@@ -1,23 +1,33 @@
1
1
  class <%= @model_name %> < ActiveRecord::Base
2
- #has_secure_password
2
+ # LOCALES = { attribute_1: 'Attribute 1', attribute_2: 'Attribute 2' }
3
+
4
+ # belongs_to
5
+ # has_many
6
+
7
+ # attr_accessor :new_attribute
8
+
9
+ # has_secure_password
3
10
 
4
- #validates_acceptance_of
5
- #validates_associated
6
- #validates_confirmation_of
7
- #validates_exclusion_of
8
- #validates_format_of
9
- #validates_inclusion_of
10
- #validates_length_of
11
- #validates_numericality_of
12
- #validates_presence_of
13
- #validates_uniqueness_of
14
- #validates_each
11
+ # validates_acceptance_of
12
+ # validates_associated
13
+ # validates_confirmation_of
14
+ # validates_exclusion_of
15
+ # validates_format_of
16
+ # validates_inclusion_of
17
+ # validates_length_of
18
+ # validates_numericality_of
19
+ # validates_presence_of
20
+ # validates_uniqueness_of
21
+ # validates_each
15
22
 
16
- #validate :custom_method
23
+ # validate :custom_method
17
24
 
18
- #def custom_method
25
+ # def custom_method
19
26
  # errors.add(:field, "that's an error") if
20
27
  # some_condition != true
21
- #end
28
+ # end
22
29
 
30
+ # def self.human_attribute_name(attribute, options = {})
31
+ # return LOCALES[attribute] || super
32
+ # end
23
33
  end
@@ -0,0 +1 @@
1
+ <h1>Some error occurred...</h1>
@@ -1,15 +1,7 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title><%= @name %></title>
5
- </head>
6
- <body>
7
- <h1>Welcome to Sinatra</h1>
8
- <h2>Powered by SinatraBand</h2>
1
+ <h1>Welcome to Sinatra</h1>
2
+ <h2>Powered by SinatraBand</h2>
9
3
 
10
- <p>
11
- You created the app called <%= @name %>.<br />
12
- Keep developing!
13
- </p>
14
- </body>
15
- </html>
4
+ <p>
5
+ You created the app called <%= @name %>.<br />
6
+ Keep developing!
7
+ </p>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @name %></title>
5
+ </head>
6
+ <body>
7
+ <%%= yield %>
8
+ </body>
9
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatraband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julio Bueno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-08 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -31,14 +31,16 @@ executables:
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - lib/templates/config/config.erb
34
35
  - lib/templates/controllers/controller.erb
35
36
  - lib/templates/models/model.erb
37
+ - lib/templates/views/layout.erb
36
38
  - lib/templates/views/index.erb
39
+ - lib/templates/views/error.erb
37
40
  - lib/templates/app.erb
38
41
  - lib/templates/Gemfile.erb
39
42
  - lib/templates/rakefile.erb
40
43
  - lib/templates/db/migrate/migration.erb
41
- - lib/templates/db/connection.erb
42
44
  - bin/app.rb
43
45
  - bin/helper.rb
44
46
  - bin/sinatraband
@@ -1,2 +0,0 @@
1
- require 'sinatra/activerecord'
2
- set :database, "mysql2://root:@localhost/<%= @name %>"