r4 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/r4 +4 -0
- data/bin/setup +7 -0
- data/lib/r4.rb +5 -0
- data/lib/r4/config.rb +12 -0
- data/lib/r4/installations/default.rb +44 -0
- data/lib/r4/installations/testing.rb +4 -0
- data/lib/r4/odin.rb +76 -0
- data/lib/r4/recipes/bootstrap.rb +9 -0
- data/lib/r4/recipes/bootstrap_app.rb +10 -0
- data/lib/r4/recipes/devise.rb +94 -0
- data/lib/r4/recipes/exception_notification.rb +10 -0
- data/lib/r4/recipes/gemfile.rb +34 -0
- data/lib/r4/recipes/gitignore.rb +8 -0
- data/lib/r4/recipes/install_questions.rb +20 -0
- data/lib/r4/recipes/lazy_high_charts.rb +18 -0
- data/lib/r4/recipes/mysql.rb +22 -0
- data/lib/r4/recipes/rspec_generators.rb +18 -0
- data/lib/r4/recipes/upload_app.rb +9 -0
- data/lib/r4/recipes/wicked_pdf.rb +35 -0
- data/lib/r4/recipes/xlsx_support.rb +6 -0
- data/lib/r4/starter.rb +116 -0
- data/lib/r4/template/.ruby-version +1 -0
- data/lib/r4/template/app/assets/javascripts/main.js.rb +11 -0
- data/lib/r4/template/app/assets/stylesheets/custom.css.scss +128 -0
- data/lib/r4/template/app/assets/stylesheets/main.css.scss +7 -0
- data/lib/r4/template/app/assets/stylesheets/theme.css +7089 -0
- data/lib/r4/template/app/assets/stylesheets/timepress.css.scss +127 -0
- data/lib/r4/template/app/controllers/users_controller.rb +106 -0
- data/lib/r4/template/app/views/layouts/application.html.erb +64 -0
- data/lib/r4/template/app/views/users/_form.html.erb +64 -0
- data/lib/r4/template/app/views/users/edit.html.erb +10 -0
- data/lib/r4/template/app/views/users/edit_password.html.erb +49 -0
- data/lib/r4/template/app/views/users/index.html.erb +36 -0
- data/lib/r4/template/app/views/users/index.json.jbuilder +4 -0
- data/lib/r4/template/app/views/users/new.html.erb +9 -0
- data/lib/r4/template/app/views/users/show.html.erb +14 -0
- data/lib/r4/template/app/views/users/show.json.jbuilder +1 -0
- data/lib/r4/template/config/initializers/html_helpers.rb +99 -0
- data/lib/r4/template/config/locales/cs.yml +307 -0
- data/lib/r4/template/lib/tasks/bootstrap.rake +20 -0
- data/lib/r4/template/lib/tasks/upload.rake +24 -0
- data/lib/r4/version.rb +3 -0
- data/r4.gemspec +29 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e4f0b657ce05f7414ac7976b530f0f0d05d49b2
|
4
|
+
data.tar.gz: 773801128438961f825665026bb5675f6e48de00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2df90ae0b0fb2fb13caba20d495ee6c8d242af4e99d6e537194e348de0b885c3835399527448de2bbc5f25d5c18cfdae61dcc18e7bd5f04749990f28ad83008
|
7
|
+
data.tar.gz: 30a9589d879512e0f1813874db3a676897cbb37b98d36cb6c7e1df1dd7736f3a5a65fe0fccc32367650f5d48b72e856f7bd986666b35522b3a7b1662151d07b7
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# R4
|
2
|
+
|
3
|
+
This gem is used for generating default project for Timepress company. However we hope it can be useful for other users as well.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
It is still not in Rubygems repository. Thus this wont work for a while.
|
10
|
+
|
11
|
+
You can clone project and use bundler to install gem locally with "rake install".
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'r4'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install r4
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Gem expects config file in home directory named .r4.yml, which should contain following:
|
28
|
+
|
29
|
+
```
|
30
|
+
mysql:
|
31
|
+
user: 'mysql_user_name'
|
32
|
+
password: 'mysql_password'
|
33
|
+
|
34
|
+
admin:
|
35
|
+
login: 'default_admin_login'
|
36
|
+
password: 'default_admin_password'
|
37
|
+
email: 'default@admin.email'
|
38
|
+
lastname: 'AdminLastName'
|
39
|
+
|
40
|
+
notifier:
|
41
|
+
email: 'email@for_exception.notifier'
|
42
|
+
|
43
|
+
server:
|
44
|
+
name: 'server_name_for_deploy_script'
|
45
|
+
port: 'ssh_port_number'
|
46
|
+
user: 'server_user_for_deploy'
|
47
|
+
```
|
48
|
+
|
49
|
+
Then you can create new application with r4 new name_of_app
|
50
|
+
Custom installations types can be specified in 'installations' directory.
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it ( https://github.com/[my-github-username]/r4/fork )
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "r4"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/r4
ADDED
data/bin/setup
ADDED
data/lib/r4.rb
ADDED
data/lib/r4/config.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# DEFAULT SETTINGS
|
2
|
+
copy '.ruby-version'
|
3
|
+
apply 'recipes/gemfile.rb'
|
4
|
+
|
5
|
+
copy 'config/initializers/html_helpers.rb'
|
6
|
+
copy 'config/locales/cs.yml'
|
7
|
+
copy 'app/assets/stylesheets/theme.css'
|
8
|
+
copy 'app/assets/stylesheets/custom.css.scss'
|
9
|
+
copy 'app/assets/stylesheets/timepress.css.scss'
|
10
|
+
|
11
|
+
remove 'app/views/layouts/application.html.erb'
|
12
|
+
copy 'app/views/layouts/application.html.erb'
|
13
|
+
|
14
|
+
apply 'recipes/bootstrap_app.rb'
|
15
|
+
apply 'recipes/upload_app.rb'
|
16
|
+
gsub_file "#{@project_path}/lib/tasks/upload.rake", /PROJECT_DIR/, @project_name
|
17
|
+
|
18
|
+
insert_into_file "#{@project_path}/config/application.rb",
|
19
|
+
after: "class Application < Rails::Application\n" do <<-RUBY
|
20
|
+
config.assets.enabled = true
|
21
|
+
config.assets.precompile += %w()
|
22
|
+
config.i18n.default_locale = :cs
|
23
|
+
config.time_zone = 'Prague'
|
24
|
+
RUBY
|
25
|
+
end
|
26
|
+
|
27
|
+
apply 'recipes/mysql.rb'
|
28
|
+
apply 'recipes/rspec_generators.rb'
|
29
|
+
apply 'recipes/exception_notification.rb'
|
30
|
+
rake 'db:drop'
|
31
|
+
rake 'db:create'
|
32
|
+
|
33
|
+
apply 'recipes/devise.rb'
|
34
|
+
apply 'recipes/bootstrap.rb'
|
35
|
+
layout_file = "#{@project_path}/app/views/layouts/application.html.erb"
|
36
|
+
remove 'app/views/layouts/application.html.erb'
|
37
|
+
copy 'app/views/layouts/application.html.erb'
|
38
|
+
gsub_file layout_file, 'PROJECT_NAME', @project_name
|
39
|
+
apply 'recipes/gitignore'
|
40
|
+
run 'git init'
|
41
|
+
run 'git add .'
|
42
|
+
run "git commit -a -m 'Initial commit'"
|
43
|
+
|
44
|
+
rake 'app:bootstrap'
|
data/lib/r4/odin.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Odin
|
2
|
+
|
3
|
+
def gsub filename, options={}, &block
|
4
|
+
puts options[:log] if options[:log]
|
5
|
+
fr = File.new(filename)
|
6
|
+
content = fr.read
|
7
|
+
fr.close
|
8
|
+
change = content.clone
|
9
|
+
block.call change
|
10
|
+
unless content==change
|
11
|
+
fw = File.new filename, 'w'
|
12
|
+
fw.write change
|
13
|
+
fw.close
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def sub filename, mark, part, options={}
|
18
|
+
File.open(filename) do |f|
|
19
|
+
content = f.read
|
20
|
+
if options[:global]
|
21
|
+
change = content.gsub mark, part
|
22
|
+
else
|
23
|
+
change = content.sub mark, part
|
24
|
+
end
|
25
|
+
unless change==content
|
26
|
+
file filename, change
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def content filename
|
32
|
+
File.open(filename).read
|
33
|
+
end
|
34
|
+
|
35
|
+
def concat filename, part
|
36
|
+
File.open(filename) do |f|
|
37
|
+
content = f.read
|
38
|
+
file filename, content + part
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def file filename, content
|
43
|
+
File.open(filename, 'w') do |f|
|
44
|
+
f.write content
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def cp from, to
|
49
|
+
system "cp #{from} #{to}"
|
50
|
+
end
|
51
|
+
def rm what
|
52
|
+
system "rm #{what}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def cp_template template_dir, path
|
56
|
+
cp "#{template_dir}/#{path}", path
|
57
|
+
end
|
58
|
+
|
59
|
+
def rake task
|
60
|
+
system "rake #{task}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def rails task
|
64
|
+
system "rails #{task}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def git task
|
68
|
+
system "git #{task}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def bundle task=''
|
72
|
+
system "bundle #{task}"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
add_gem 'bootstrap-generators'
|
2
|
+
add_gem 'bootstrap-select-rails'
|
3
|
+
add_gem 'scrollbar-rails'
|
4
|
+
run 'bundle install'
|
5
|
+
# TODO removing is probably not good idea when adding bootstrap to existing project
|
6
|
+
remove 'app/views/layouts/application.html.erb'
|
7
|
+
system "rails generate bootstrap:install"
|
8
|
+
sub "#{@project_path}/app/views/layouts/application.html.erb", /<title>.*?<\/title>/, "<title>#{@project_label}</title>"
|
9
|
+
sub "#{@project_path}/app/views/layouts/application.html.erb", /Project name/, @project_label
|
@@ -0,0 +1,10 @@
|
|
1
|
+
path = 'lib/tasks/bootstrap.rake'
|
2
|
+
bootstrap_file = "#{@project_path}/#{path}"
|
3
|
+
copy path
|
4
|
+
|
5
|
+
gsub_file bootstrap_file, 'ADMIN_LOGIN', Config.settings['admin']['login']
|
6
|
+
gsub_file bootstrap_file, 'ADMIN_PASSWORD', Config.settings['admin']['password']
|
7
|
+
gsub_file bootstrap_file, 'ADMIN_EMAIL', Config.settings['admin']['email']
|
8
|
+
gsub_file bootstrap_file, 'ADMIN_LASTNAME', Config.settings['admin']['lastname']
|
9
|
+
|
10
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
|
2
|
+
# TODO add checking for existing devise in project
|
3
|
+
add_gem 'devise'
|
4
|
+
|
5
|
+
run 'bundle install'
|
6
|
+
run 'rails g devise:install'
|
7
|
+
run 'rails g devise User'
|
8
|
+
|
9
|
+
insert_into_file "#{@project_path}/app/controllers/application_controller.rb",
|
10
|
+
after: "class ApplicationController < ActionController::Base\n" do <<-RUBY
|
11
|
+
protect_from_forgery with: :exception
|
12
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
13
|
+
before_action :authenticate_user!
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def configure_permitted_parameters
|
18
|
+
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :password, :remember_me) }
|
19
|
+
devise_parameter_sanitizer.for(:account_update) { |u|
|
20
|
+
u.permit(:password, :password_confirmation, :current_password)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def only_for_user
|
25
|
+
complain unless current_user
|
26
|
+
end
|
27
|
+
|
28
|
+
def only_for_admin
|
29
|
+
complain unless current_user && current_user.admin?
|
30
|
+
end
|
31
|
+
|
32
|
+
def complain
|
33
|
+
# TODO - 404 or just polite 'permissions denied'
|
34
|
+
raise StandardError.new 'permissions denied'
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
|
39
|
+
insert_into_file "#{@project_path}/app/models/user.rb",
|
40
|
+
after: "class User < ActiveRecord::Base\n" do <<-RUBY
|
41
|
+
def display_name
|
42
|
+
[firstname, lastname].join(' ')
|
43
|
+
end
|
44
|
+
|
45
|
+
RUBY
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
#TODO check for devise
|
50
|
+
user_migrate_filename = Dir.glob("#{@project_path}/db/migrate/*devise_create_users.rb").first
|
51
|
+
unless File.open(user_migrate_filename).read=~/string :login/
|
52
|
+
gsub_file user_migrate_filename, 't.string :email,', "t.string :login, null: false, default: ''\n t.string :email,"
|
53
|
+
gsub_file user_migrate_filename, ':encrypted_password, null: false, default: ""' do <<-RUBY
|
54
|
+
:encrypted_password, null: false, default: ''
|
55
|
+
t.string :firstname, null: false, default: ''
|
56
|
+
t.string :lastname, null: false, default: ''
|
57
|
+
t.boolean :admin, null: false, default: false
|
58
|
+
RUBY
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# part for editing users and own password
|
63
|
+
copy 'app/controllers/users_controller.rb'
|
64
|
+
Dir.mkdir "#{@project_path}/app/views/users"
|
65
|
+
directory 'app/views/users', "#{@project_path}/app/views/users"
|
66
|
+
|
67
|
+
# different options can be used - this one is allowing admins to change passwords to other users
|
68
|
+
# - edit_user_registration_path can be used instead - then only user can change his/her own password
|
69
|
+
|
70
|
+
gsub_file "#{@project_path}/config/routes.rb", 'devise_for :users' do
|
71
|
+
<<EOF
|
72
|
+
devise_for :users
|
73
|
+
scope "/admin" do
|
74
|
+
resources :users
|
75
|
+
end
|
76
|
+
|
77
|
+
get 'edit_password/:id' => 'users#edit_password'
|
78
|
+
resource :user, only: [:edit] do
|
79
|
+
collection do
|
80
|
+
patch 'update_password'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
get 'edit_own_password' => 'users#edit_own_password'
|
85
|
+
EOF
|
86
|
+
end
|
87
|
+
|
88
|
+
gsub_file "#{@project_path}/config/routes.rb", "# root 'welcome#index'" do
|
89
|
+
"root 'users#index'"
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
run 'rake app:bootstrap'
|
94
|
+
run 'rake db:migrate'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
add_gem 'exception_notification'
|
2
|
+
|
3
|
+
run 'bundle install'
|
4
|
+
|
5
|
+
config_file = "#{@project_path}/config/initializers/exception_notification.rb"
|
6
|
+
|
7
|
+
run 'rails g exception_notification:install' unless File.exist? config_file
|
8
|
+
gsub_file config_file, "\"[ERROR] \"", "\"[#{@project_label} ERROR] \""
|
9
|
+
gsub_file config_file, "%{\"Notifier\" <notifier@example.com>},", "%{\"#{@project_label} Notifier\" #{Config.settings['notifier']['email']}},"
|
10
|
+
gsub_file config_file, "%w{exceptions@example.com}', '%w{#{Config.settings['notifier']['email']}}"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
gemfile = "#{@project_path}/Gemfile"
|
2
|
+
gsub_file gemfile, "gem 'sqlite3'", "gem 'mysql2', '0.3.18'"
|
3
|
+
|
4
|
+
insert_into_file gemfile, after: "group :development, :test do\n" do
|
5
|
+
<<EOF
|
6
|
+
gem 'rspec-rails'
|
7
|
+
gem 'factory_girl_rails'
|
8
|
+
gem 'timecop'
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'spring-commands-rspec'
|
11
|
+
EOF
|
12
|
+
end
|
13
|
+
|
14
|
+
insert_into_file gemfile, after: "group :development do\n" do
|
15
|
+
<<EOF
|
16
|
+
gem 'better_errors'
|
17
|
+
gem 'binding_of_caller'
|
18
|
+
gem 'meta_request'
|
19
|
+
gem 'bullet'
|
20
|
+
EOF
|
21
|
+
end
|
22
|
+
|
23
|
+
append_to_file gemfile do
|
24
|
+
<<EOF
|
25
|
+
group :test do
|
26
|
+
gem 'faker'
|
27
|
+
gem 'capybara'
|
28
|
+
end
|
29
|
+
|
30
|
+
gem 'font-awesome-rails'
|
31
|
+
gem 'quiet_assets'
|
32
|
+
gem 'jquery-ui-rails'
|
33
|
+
EOF
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
if yes? 'Do you want to prepare database config for mysql?'
|
2
|
+
apply 'recipes/mysql.rb'
|
3
|
+
end
|
4
|
+
|
5
|
+
if yes? 'Do you want to add rspec generators to application.rb?'
|
6
|
+
apply 'recipes/rspec_generators.rb'
|
7
|
+
end
|
8
|
+
|
9
|
+
if yes? 'Do you want to add exception notification?'
|
10
|
+
apply 'recipes/exception_notification.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
if yes? 'do you want to drop and create a database?'
|
14
|
+
rake 'db:drop'
|
15
|
+
rake 'db:create'
|
16
|
+
end
|
17
|
+
|
18
|
+
if yes? 'Do you want to add devise to project?'
|
19
|
+
apply 'recipes/devise.rb'
|
20
|
+
end
|