r4 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +64 -0
  4. data/Rakefile +2 -0
  5. data/bin/console +14 -0
  6. data/bin/r4 +4 -0
  7. data/bin/setup +7 -0
  8. data/lib/r4.rb +5 -0
  9. data/lib/r4/config.rb +12 -0
  10. data/lib/r4/installations/default.rb +44 -0
  11. data/lib/r4/installations/testing.rb +4 -0
  12. data/lib/r4/odin.rb +76 -0
  13. data/lib/r4/recipes/bootstrap.rb +9 -0
  14. data/lib/r4/recipes/bootstrap_app.rb +10 -0
  15. data/lib/r4/recipes/devise.rb +94 -0
  16. data/lib/r4/recipes/exception_notification.rb +10 -0
  17. data/lib/r4/recipes/gemfile.rb +34 -0
  18. data/lib/r4/recipes/gitignore.rb +8 -0
  19. data/lib/r4/recipes/install_questions.rb +20 -0
  20. data/lib/r4/recipes/lazy_high_charts.rb +18 -0
  21. data/lib/r4/recipes/mysql.rb +22 -0
  22. data/lib/r4/recipes/rspec_generators.rb +18 -0
  23. data/lib/r4/recipes/upload_app.rb +9 -0
  24. data/lib/r4/recipes/wicked_pdf.rb +35 -0
  25. data/lib/r4/recipes/xlsx_support.rb +6 -0
  26. data/lib/r4/starter.rb +116 -0
  27. data/lib/r4/template/.ruby-version +1 -0
  28. data/lib/r4/template/app/assets/javascripts/main.js.rb +11 -0
  29. data/lib/r4/template/app/assets/stylesheets/custom.css.scss +128 -0
  30. data/lib/r4/template/app/assets/stylesheets/main.css.scss +7 -0
  31. data/lib/r4/template/app/assets/stylesheets/theme.css +7089 -0
  32. data/lib/r4/template/app/assets/stylesheets/timepress.css.scss +127 -0
  33. data/lib/r4/template/app/controllers/users_controller.rb +106 -0
  34. data/lib/r4/template/app/views/layouts/application.html.erb +64 -0
  35. data/lib/r4/template/app/views/users/_form.html.erb +64 -0
  36. data/lib/r4/template/app/views/users/edit.html.erb +10 -0
  37. data/lib/r4/template/app/views/users/edit_password.html.erb +49 -0
  38. data/lib/r4/template/app/views/users/index.html.erb +36 -0
  39. data/lib/r4/template/app/views/users/index.json.jbuilder +4 -0
  40. data/lib/r4/template/app/views/users/new.html.erb +9 -0
  41. data/lib/r4/template/app/views/users/show.html.erb +14 -0
  42. data/lib/r4/template/app/views/users/show.json.jbuilder +1 -0
  43. data/lib/r4/template/config/initializers/html_helpers.rb +99 -0
  44. data/lib/r4/template/config/locales/cs.yml +307 -0
  45. data/lib/r4/template/lib/tasks/bootstrap.rake +20 -0
  46. data/lib/r4/template/lib/tasks/upload.rake +24 -0
  47. data/lib/r4/version.rb +3 -0
  48. data/r4.gemspec +29 -0
  49. 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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in r4.gemspec
4
+ gemspec
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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
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
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'r4'
4
+ Starter.start(ARGV)
data/bin/setup ADDED
@@ -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
data/lib/r4.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "r4/version"
2
+ require 'r4/starter'
3
+ module R4
4
+ # some code
5
+ end
data/lib/r4/config.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'yaml'
2
+
3
+ class Config
4
+
5
+ def self.settings
6
+ if File.exists? "#{ENV['HOME']}/.r4.yml"
7
+ YAML::load_file("#{ENV['HOME']}/.r4.yml")
8
+ else
9
+ 'You need to create ~/.r4.yml file, check github for example.'
10
+ end
11
+ end
12
+ end
@@ -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'
@@ -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"
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,8 @@
1
+ append_to_file "#{@project_path}/.gitignore" do
2
+ <<EOF
3
+ /config/database.yml
4
+ /log/*.log
5
+ /tmp
6
+ /db/schema.rb
7
+ EOF
8
+ 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