gempire 0.0.8

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b841f782f7dc31565994619ebfd1beb145ca94a
4
+ data.tar.gz: 4dcb1c87fe649d411ed249a2a1941ca6c87bf57c
5
+ SHA512:
6
+ metadata.gz: f2ca1790cfa8fd2699a224632c103f7bdf94b02111f3dfe7c60481f1f6c8bdadf398136239c45f65143c8d28152b5be14bc5d9339d4a7aa242445d02bf5dee4b
7
+ data.tar.gz: e6c7679a43c9cdd4ea38fcc8473d1fac71926948f2c4c5882f10998d9f44078137e8ae3b8f6636d4a38bb140caa6eba10a100fd118aad0f0040c8bc0a9bdec23
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gempire.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Andrew Sinner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Gempire
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gempire'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gempire
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/gempire/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require 'gem_release'
2
+
3
+ task :build do
4
+ puts GemVersion.next_version
5
+ end
6
+
7
+ # require "bundler/gem_tasks"
8
+ #
9
+ # ''
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby -wU
2
+ require 'gempire'
3
+
4
+ puts Gempire::Generator.start(ARGV)
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gempire/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gempire"
8
+ spec.version = Gempire::VERSION
9
+ spec.authors = ["Andrew Sinner"]
10
+ spec.email = ["andrewsinner@gmail.com"]
11
+ spec.summary = "Andrew Sinner's gem for scaffolding sweet rails apps"
12
+ spec.description = "This gem helps scaffold rails apps according to some conventions used by Andrew Sinner."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+
22
+ spec.add_development_dependency "thor"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,6 @@
1
+ require "gempire/version"
2
+ require "gempire/cli"
3
+
4
+ module Gempire
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,206 @@
1
+ require 'thor'
2
+
3
+ module Gempire
4
+ class Generator < Thor
5
+ desc 'generate', 'Run this command with options to generate code for you. Make sure to run this from the project root.'
6
+
7
+ option :with_users, desc: "Generates a user model with the following attributes:
8
+ first_name
9
+ last_name
10
+ email
11
+ password_digest
12
+
13
+ This option will add the 'bcrypt' gem to your Gemfile for you and enable
14
+ 'has_secure_password' on the User type."
15
+
16
+ option :with_bootstrap, desc: "Installs bootstrap via bower into the
17
+ vendor/assets/bower_components dir. Please make sure to have bower installed
18
+ on your machine before using this flag"
19
+
20
+ def generate
21
+
22
+ ##
23
+ # Add default gemset
24
+ add_default_gemset
25
+
26
+ puts 'Default gemset added'
27
+
28
+ ##
29
+ # Return early if no options were specified
30
+ return 'Please specify an option. Use gempire --help to see a list of options.' if options.empty?
31
+
32
+ ##
33
+ # This is the control structure for generating everything related to the
34
+ # the user model
35
+ if options[:with_users]
36
+ ##
37
+ # Executes the rails generator for the user model and passes in the default
38
+ # attributes
39
+ exec 'rails generate model User first_name last_name email password_digest'
40
+
41
+ user_content = <<-ruby
42
+ # Settings provided by the ledermann-rails-settings gem
43
+ has_settings do |s|
44
+ s.key :time_zone, defaults: {
45
+ zone: 'UTC'
46
+ }
47
+ end
48
+ ruby
49
+
50
+ ##
51
+ # Add the has_secure_password method to the user model
52
+ lines = File.readlines('app/models/user.rb')
53
+ lines.insert(1, "\thas_secure_password")
54
+ File.open('app/models/user.rb', 'w') do |f|
55
+ lines.each do |l|
56
+ f.puts l
57
+ end
58
+ end
59
+
60
+ ##
61
+ # Create the log in functionality. This will create the sessions_controller
62
+ template_path = File.expand_path('../templates/sessions_controller.rb', File.dirname(__FILE__))
63
+ File.open('app/controllers/sessions_controller.rb', 'w') do |dest|
64
+ File.open(template_path) do |template|
65
+ dest.puts(template.read)
66
+ end
67
+ end
68
+
69
+ ##
70
+ # Now write some convenience methods to the application_controller
71
+ definition = <<-definition
72
+ helper_method :current_user
73
+ helper_method :signed_in?
74
+
75
+ def current_user
76
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
77
+ end
78
+
79
+ def signed_in?
80
+ current_user.present?
81
+ end
82
+
83
+ def sign_in(user)
84
+ session[:user_id] = user.id
85
+ end
86
+
87
+ def after_sign_in
88
+ redirect_to dashboard_path
89
+ end
90
+
91
+ def after_sign_out
92
+ redirect_to sign_in_path
93
+ end
94
+ definition
95
+
96
+ ##
97
+ # Read out the existing application_controller
98
+ lines = File.readlines('app/controllers/application_controller.rb')
99
+ lines.insert(1, definition)
100
+
101
+ ##
102
+ # Write back the application_controller with the new after_sign_in_method
103
+ File.open('app/controllers/application_controller.rb', 'w') do |f|
104
+ lines.each {|l| f.puts(l)}
105
+ end
106
+
107
+ routes = <<-routes
108
+ get '/sign-in' => 'sessions#new', as: 'sign_in'
109
+ post '/sessions' => 'sessions#create'
110
+ delete '/sessions' => 'sessions#delete'
111
+ routes
112
+
113
+ ##
114
+ # Write the sessions routes to the routes.rb file
115
+ lines = File.readlines('app/config/routes.rb')
116
+ lines.insert(1, routes)
117
+
118
+ File.open('app/config/routes.rb') do |f|
119
+ lines.each {|l| f.puts(l)}
120
+ end
121
+
122
+ ##
123
+ # Make the views/sessions directory if it's not already there
124
+ if File.directory?('app/views/sesions') === false
125
+ Dir.mkdir('app/views/sessions')
126
+ end
127
+
128
+ ##
129
+ # Create the login form
130
+ if options[:with_bootstrap]
131
+ template_path = File.expand_path('../templates/sign_in_form_bootstrap.html.erb', File.dirname(__FILE__))
132
+ File.open('app/views/sessions/new.html.erb') do |dest|
133
+ File.open(template_path) do |template|
134
+ dest.write(template.read)
135
+ end
136
+ end
137
+ else
138
+ template_path = File.expand_path('../templates/sign_in_form.html.erb', File.dirname(__FILE__))
139
+ File.open('app/views/sessions/new.html.erb') do |dest|
140
+ File.open(template_path) do |template|
141
+ dest.write(template.read)
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ ##
148
+ # Control structure for using bootstrap
149
+ if options[:with_bootstrap]
150
+ text = <<-bower
151
+ {
152
+ "directory": "vendor/assets/bower_components"
153
+ }
154
+ bower
155
+
156
+ File.open('.bowerrc', 'w+') do |dest|
157
+ dest.write(text)
158
+ end
159
+
160
+
161
+ exec 'mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss'
162
+
163
+ File.open('app/assets/stylesheets/application.scss', 'w+') do |dest|
164
+ dest.puts("@import 'bootstrap/dist/css/bootstrap';")
165
+ end
166
+
167
+ ##
168
+ # Find what line to insert the bower components
169
+ start_at = 0
170
+ lines = File.readlines('config/application.rb')
171
+ lines.each_with_index do |line, index|
172
+ if line.include?('Rails::Application')
173
+ starts_at = index
174
+ break
175
+ end
176
+ end
177
+ lines.insert(index, "\t\tconfig.assets.paths << Rails.root.join('bower_components')")
178
+ File.open('config/application.rb', 'w') do |dest|
179
+ lines.each {|line| dest.puts(line)}
180
+ end
181
+
182
+ # exec 'bower install --save bootstrap'
183
+ end
184
+ end
185
+
186
+
187
+
188
+ ##
189
+ # This method will add the default gem set to the Gemfile
190
+ def add_default_gemset
191
+ gems = <<-gems
192
+ gem 'simple_form'
193
+ gem 'stripe'
194
+ gem 'ledermann-rails-settings'
195
+ gem 'factory_girl_rails'
196
+ gem 'faker'
197
+ gem 'bcrypt', '~> 3.1.7'
198
+ gems
199
+
200
+
201
+ File.open('Gemfile', 'a') do |f|
202
+ f.puts(gems)
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,3 @@
1
+ module Gempire
2
+ VERSION = "0.0.8"
3
+ end
@@ -0,0 +1,22 @@
1
+ class SessionsController < ApplicationController
2
+ def new
3
+ end
4
+
5
+ def create
6
+ user = User.where(email: params[:user][:email]).first if params[:user]
7
+ if user && params[:user] && user.authenticate(params[:user][:password])
8
+ flash.clear
9
+ session[:user_id] = user.id
10
+ after_sign_in
11
+ else
12
+ flash[:error] = "Invalid email / password combination"
13
+ render :new
14
+ end
15
+ end
16
+
17
+ def destroy
18
+ session[:user_id]
19
+ flash[:success] = 'You have been logged out'
20
+ redirect_to after_sign_out
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ <%= simple_form_for :user, url: '/sign-in', method: :post do |f| %>
2
+ <%= f.input :email %>
3
+ <%= f.input :password %>
4
+ <%= f.submit %>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <%= simple_form_for :user, url: '/sign-in', method: :post, html: {class: 'form-horizontal'} do |f| %>
2
+ <%= f.input :email %>
3
+ <%= f.input :password %>
4
+ <%= f.submit %>
5
+ <% end %>
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gempire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Sinner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: This gem helps scaffold rails apps according to some conventions used
56
+ by Andrew Sinner.
57
+ email:
58
+ - andrewsinner@gmail.com
59
+ executables:
60
+ - gempire
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/gempire
70
+ - gempire.gemspec
71
+ - lib/gempire.rb
72
+ - lib/gempire/cli.rb
73
+ - lib/gempire/version.rb
74
+ - lib/templates/sessions_controller.rb
75
+ - lib/templates/sign_in_form.html.erb
76
+ - lib/templates/sign_in_form_bootstrap.html.erb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.5
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Andrew Sinner's gem for scaffolding sweet rails apps
101
+ test_files: []
102
+ has_rdoc: