r5 0.1.5

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +69 -0
  4. data/Rakefile +2 -0
  5. data/bin/console +14 -0
  6. data/bin/r5 +4 -0
  7. data/bin/setup +7 -0
  8. data/lib/r5.rb +5 -0
  9. data/lib/r5/config.rb +12 -0
  10. data/lib/r5/installations/default.rb +53 -0
  11. data/lib/r5/installations/testing.rb +4 -0
  12. data/lib/r5/odin.rb +76 -0
  13. data/lib/r5/recipes/bootstrap.rb +9 -0
  14. data/lib/r5/recipes/bootstrap_app.rb +10 -0
  15. data/lib/r5/recipes/devise.rb +94 -0
  16. data/lib/r5/recipes/exception_notification.rb +10 -0
  17. data/lib/r5/recipes/gemfile.rb +41 -0
  18. data/lib/r5/recipes/gitignore.rb +8 -0
  19. data/lib/r5/recipes/install_questions.rb +20 -0
  20. data/lib/r5/recipes/lazy_high_charts.rb +18 -0
  21. data/lib/r5/recipes/mail_settings.rb +22 -0
  22. data/lib/r5/recipes/mysql.rb +22 -0
  23. data/lib/r5/recipes/rspec_generators.rb +18 -0
  24. data/lib/r5/recipes/upload_app.rb +9 -0
  25. data/lib/r5/recipes/wicked_pdf.rb +35 -0
  26. data/lib/r5/recipes/xlsx_support.rb +6 -0
  27. data/lib/r5/starter.rb +116 -0
  28. data/lib/r5/template/.ruby-version +1 -0
  29. data/lib/r5/template/app/assets/javascripts/main.js.rb +11 -0
  30. data/lib/r5/template/app/assets/stylesheets/custom.css.scss +128 -0
  31. data/lib/r5/template/app/assets/stylesheets/main.css.scss +7 -0
  32. data/lib/r5/template/app/assets/stylesheets/theme.css +7089 -0
  33. data/lib/r5/template/app/assets/stylesheets/timepress.css.scss +127 -0
  34. data/lib/r5/template/app/controllers/users_controller.rb +106 -0
  35. data/lib/r5/template/app/views/layouts/application.html.erb +64 -0
  36. data/lib/r5/template/app/views/users/_form.html.erb +64 -0
  37. data/lib/r5/template/app/views/users/edit.html.erb +10 -0
  38. data/lib/r5/template/app/views/users/edit_password.html.erb +49 -0
  39. data/lib/r5/template/app/views/users/index.html.erb +36 -0
  40. data/lib/r5/template/app/views/users/index.json.jbuilder +4 -0
  41. data/lib/r5/template/app/views/users/new.html.erb +9 -0
  42. data/lib/r5/template/app/views/users/show.html.erb +14 -0
  43. data/lib/r5/template/app/views/users/show.json.jbuilder +1 -0
  44. data/lib/r5/template/config/initializers/html_helpers.rb +99 -0
  45. data/lib/r5/template/config/locales/cs.yml +307 -0
  46. data/lib/r5/template/lib/tasks/bootstrap.rake +20 -0
  47. data/lib/r5/template/lib/tasks/upload.rake +24 -0
  48. data/lib/r5/version.rb +3 -0
  49. data/r5.gemspec +29 -0
  50. metadata +137 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7330aa9a09ef0653d10c9cdf5d05d69cad793ab
4
+ data.tar.gz: a88fcdd4f52c7ab2dfc43b2c3bd42e11eb09e586
5
+ SHA512:
6
+ metadata.gz: bc3ea8fe70df4e35299374630f722736ed2611e53e431807b8c1f6049f1b93891802210a7863aa707b2aa9c620fca6d8cbaf343ece64f4e0790440ef53f134c0
7
+ data.tar.gz: 45051737b03cc0bf0977969e136bb89a8312ef27ef3579046ee338a34b8bd9bb4921e3786de1a927e85a98bfc84a7a1d3d2813e2c28bad3089bfcd6353d12c66
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in r5.gemspec
4
+ gemspec
@@ -0,0 +1,69 @@
1
+ # R5
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 locally
6
+
7
+ You can clone project and use bundler to install gem locally with "rake install".
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'r5'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install r5
24
+
25
+ ## Usage
26
+
27
+ Gem expects config file in home directory named .r5.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 r5 new name_of_app.
50
+ Custom installations types can be specified in 'installations' directory.
51
+
52
+ ## TODO
53
+
54
+ 1. provide deploy.sh for upload.rake task to actually work for others
55
+ 2. Add testing for Rails presence before running installation
56
+
57
+ ## Development
58
+
59
+ 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.
60
+
61
+ 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).
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( https://github.com/[my-github-username]/r5/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "r5"
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/r5 ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'r5'
4
+ Starter.start(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "r5/version"
2
+ require 'r5/starter'
3
+ module R5
4
+ # some code
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'yaml'
2
+
3
+ class Config
4
+
5
+ def self.settings
6
+ if File.exists? "#{ENV['HOME']}/.r5.yml"
7
+ YAML::load_file("#{ENV['HOME']}/.r5.yml")
8
+ else
9
+ 'You need to create ~/.r5.yml file, check github for example.'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,53 @@
1
+ # DEFAULT SETTINGS
2
+ # TODO check ruby version on system and use it in ruby version
3
+ copy '.ruby-version'
4
+ apply 'recipes/gemfile.rb'
5
+ run 'bundle install'
6
+
7
+ copy 'config/initializers/html_helpers.rb'
8
+ copy 'config/locales/cs.yml'
9
+ copy 'app/assets/stylesheets/theme.css'
10
+ copy 'app/assets/stylesheets/custom.css.scss'
11
+ copy 'app/assets/stylesheets/timepress.css.scss'
12
+
13
+ remove 'app/views/layouts/application.html.erb'
14
+ copy 'app/views/layouts/application.html.erb'
15
+
16
+ apply 'recipes/bootstrap_app.rb'
17
+ apply 'recipes/upload_app.rb'
18
+ gsub_file "#{@project_path}/lib/tasks/upload.rake", /PROJECT_DIR/, @project_name
19
+
20
+ insert_into_file "#{@project_path}/config/application.rb",
21
+ after: "class Application < Rails::Application\n" do <<-RUBY
22
+ config.assets.enabled = true
23
+ config.assets.precompile += %w()
24
+ config.i18n.default_locale = :cs
25
+ config.time_zone = 'Prague'
26
+ RUBY
27
+ end
28
+
29
+ apply 'recipes/mysql.rb'
30
+ apply 'recipes/rspec_generators.rb'
31
+ apply 'recipes/exception_notification.rb'
32
+ rake 'db:drop'
33
+ rake 'db:create'
34
+
35
+ apply 'recipes/devise.rb'
36
+ apply 'recipes/bootstrap.rb'
37
+ layout_file = "#{@project_path}/app/views/layouts/application.html.erb"
38
+ remove 'app/views/layouts/application.html.erb'
39
+ copy 'app/views/layouts/application.html.erb'
40
+ apply 'recipes/mail_settings.rb'
41
+ gsub_file layout_file, 'PROJECT_NAME', @project_name
42
+ apply 'recipes/gitignore.rb'
43
+ run 'git init'
44
+ run 'git add .'
45
+ run "git commit -a -m 'Initial commit'"
46
+
47
+ todo =
48
+ <<TEXT
49
+ Check mail configuration in config/environments/production.rb for your server
50
+ Check upload.rake task for your server
51
+ TEXT
52
+
53
+ say todo, :green
@@ -0,0 +1,4 @@
1
+ apply 'installations/default.rb'
2
+ # for testing project starter
3
+ run "rails g scaffold Article name:string body:text"
4
+ rake "db:migrate"
@@ -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 < ApplicationRecord\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,41 @@
1
+ gemfile = "#{@project_path}/Gemfile"
2
+ gsub_file gemfile, "gem 'sqlite3'", "gem 'mysql2'"
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
+ begin
15
+ insert_into_file gemfile, after: "group :development do\n" do
16
+ <<EOF
17
+ gem 'better_errors'
18
+ gem 'binding_of_caller'
19
+ gem 'meta_request'
20
+ gem 'bullet'
21
+ EOF
22
+ end
23
+
24
+ end
25
+
26
+ append_to_file gemfile do
27
+ <<EOF
28
+ group :test do
29
+ gem 'faker'
30
+ gem 'capybara'
31
+ end
32
+
33
+ gem 'font-awesome-rails'
34
+ gem 'quiet_assets'
35
+ gem 'jquery-ui-rails'
36
+
37
+ # make content_tag temporarily available
38
+ gem 'record_tag_helper', '~> 1.0'
39
+ EOF
40
+ end
41
+