core-generators 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.textile +51 -0
- data/Rakefile +2 -0
- data/core-generators.gemspec +21 -0
- data/lib/core-generators.rb +6 -0
- data/lib/core/inherited_resource_controller.rb +10 -0
- data/lib/core/paginated_controller.rb +12 -0
- data/lib/core/version.rb +3 -0
- data/lib/generators/core/install/install_generator.rb +132 -0
- data/lib/generators/core/install/templates/bootstrap.rake +43 -0
- data/lib/generators/core/install/templates/locales/core.en.yml +20 -0
- data/lib/generators/core/install/templates/locales/core.es.yml +17 -0
- data/lib/generators/core/install/templates/settings.yml +17 -0
- data/lib/generators/core/install/templates/simple_form_custom.rb +58 -0
- data/lib/generators/core/layout/layout_generator.rb +42 -0
- data/lib/generators/core/layout/templates/core.js +113 -0
- data/lib/generators/core/layout/templates/core_helper.rb +114 -0
- data/lib/generators/core/layout/templates/images/arrow.png +0 -0
- data/lib/generators/core/layout/templates/images/boxbar-background.png +0 -0
- data/lib/generators/core/layout/templates/images/button-background-active.png +0 -0
- data/lib/generators/core/layout/templates/images/button-background.png +0 -0
- data/lib/generators/core/layout/templates/images/buttons/cross.png +0 -0
- data/lib/generators/core/layout/templates/images/buttons/edit.png +0 -0
- data/lib/generators/core/layout/templates/images/buttons/key.png +0 -0
- data/lib/generators/core/layout/templates/images/buttons/tick.png +0 -0
- data/lib/generators/core/layout/templates/images/menubar-background.png +0 -0
- data/lib/generators/core/layout/templates/stylesheets/base.sass +366 -0
- data/lib/generators/core/layout/templates/stylesheets/override.sass +1 -0
- data/lib/generators/core/layout/templates/stylesheets/style.sass +434 -0
- data/lib/generators/core/layout/templates/views/haml/_sidebar.html.haml +14 -0
- data/lib/generators/core/layout/templates/views/haml/layout.html.haml +38 -0
- data/lib/generators/core/scaffold/scaffold_generator.rb +125 -0
- data/lib/generators/core/scaffold/templates/controller.rb +10 -0
- data/lib/generators/core/scaffold/templates/helper.rb +3 -0
- data/lib/generators/core/scaffold/templates/migration.rb +16 -0
- data/lib/generators/core/scaffold/templates/model.rb +5 -0
- data/lib/generators/core/scaffold/templates/views/haml/_collection.html.haml +25 -0
- data/lib/generators/core/scaffold/templates/views/haml/_form.html.haml +13 -0
- data/lib/generators/core/scaffold/templates/views/haml/_search.html.haml +7 -0
- data/lib/generators/core/scaffold/templates/views/haml/edit.html.haml +11 -0
- data/lib/generators/core/scaffold/templates/views/haml/index.html.haml +8 -0
- data/lib/generators/core/scaffold/templates/views/haml/index.js.haml +1 -0
- data/lib/generators/core/scaffold/templates/views/haml/new.html.haml +12 -0
- data/lib/generators/core/scaffold/templates/views/haml/show.html.haml +19 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
h1. Core Generators
|
2
|
+
|
3
|
+
h2. Description
|
4
|
+
|
5
|
+
Scaffold generator, perfect for a new Rails 3 app. It features pagination, search, sort, and it's based on lots of known rubygems.
|
6
|
+
|
7
|
+
* inherited_resources
|
8
|
+
* show_for
|
9
|
+
* simple_form
|
10
|
+
* will_paginate
|
11
|
+
* haml
|
12
|
+
* web-app-theme
|
13
|
+
* meta-search
|
14
|
+
|
15
|
+
* nifty-generators (by Ryan bates) (totally ripped off)
|
16
|
+
|
17
|
+
h2. Instructions
|
18
|
+
|
19
|
+
h3. Create your app
|
20
|
+
|
21
|
+
<pre>
|
22
|
+
rails new APP_NAME
|
23
|
+
</pre>
|
24
|
+
|
25
|
+
h3. Configure Gemfile dependency
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
gem 'core-generators', :group => :development
|
29
|
+
</pre>
|
30
|
+
|
31
|
+
h3. Run Core Installer Generator
|
32
|
+
|
33
|
+
<pre>
|
34
|
+
rails generate core:installer
|
35
|
+
</pre>
|
36
|
+
|
37
|
+
h3. Run Core Installer Layout
|
38
|
+
|
39
|
+
<pre>
|
40
|
+
rails generate core:layout LAYOUT_NAME
|
41
|
+
</pre>
|
42
|
+
|
43
|
+
h3. Run Core Installer Scaffold
|
44
|
+
|
45
|
+
<pre>
|
46
|
+
rails generate core:scaffold MODEL attributes:types actions
|
47
|
+
</pre>
|
48
|
+
|
49
|
+
h2. Disclaimer.
|
50
|
+
|
51
|
+
It's very opinionated. This is how I use it, so it may not be of your taste.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "core/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "core-generators"
|
7
|
+
s.version = Core::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["lucasefe"]
|
10
|
+
s.email = ["lucasefe@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{core generators used by me}
|
13
|
+
s.description = %q{core generators used by me}
|
14
|
+
|
15
|
+
s.rubyforge_project = "core-generators"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Core
|
2
|
+
module PaginatedController
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
def collection
|
7
|
+
@search = end_of_association_chain.search(params[:search])
|
8
|
+
get_collection_ivar || set_collection_ivar(@search.paginate(:page => params[:page], :per_page => 10))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/core/version.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
class Core::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def copy_load_setting_file
|
5
|
+
copy_file 'settings.yml', 'config/settings.yml'
|
6
|
+
initializer '001_load_config.rb', <<-FILE
|
7
|
+
require "ostruct"
|
8
|
+
conf = YAML.load(ERB.new(File.read("#{Rails.root}/config/settings.yml")).result)[Rails.env].symbolize_keys
|
9
|
+
APP_CONFIG = OpenStruct.new(conf)
|
10
|
+
FILE
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_dependencies_to_gemfile
|
14
|
+
# General
|
15
|
+
gem 'ffaker'
|
16
|
+
gem 'haml-rails'
|
17
|
+
gem 'inherited_resources', '1.1.2'
|
18
|
+
gem 'jquery-rails', '0.2.6'
|
19
|
+
gem 'meta_search'
|
20
|
+
gem 'mysql2', '0.2.6'
|
21
|
+
gem 'show_for'
|
22
|
+
gem 'simple-navigation'
|
23
|
+
gem 'simple_form', '1.3.0'
|
24
|
+
gem 'whenever', '0.6.2'
|
25
|
+
gem 'will_paginate', '3.0.pre2'
|
26
|
+
|
27
|
+
# Development
|
28
|
+
gem 'annotate', :group => :development
|
29
|
+
gem 'irbtools', :group => :development, :require => false
|
30
|
+
|
31
|
+
# Test
|
32
|
+
with_options(:group => [:development, :test]) do |g|
|
33
|
+
g.gem 'delorean'
|
34
|
+
g.gem 'factory_girl', '2.0.0.beta1'
|
35
|
+
g.gem 'factory_girl_rails', '1.1.beta1'
|
36
|
+
g.gem 'fuubar'
|
37
|
+
g.gem 'rspec-rails', '2.4.1'
|
38
|
+
g.gem 'shoulda'
|
39
|
+
g.gem 'steak', '1.0.1'
|
40
|
+
end
|
41
|
+
|
42
|
+
ask("Before answering, please, run bundle install in another terminal (Sorry):")
|
43
|
+
end
|
44
|
+
|
45
|
+
def copy_locale_file
|
46
|
+
copy_file "locales/core.en.yml", "config/locales/core.en.yml"
|
47
|
+
copy_file "locales/core.es.yml", "config/locales/core.es.yml"
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup_git_configutation
|
51
|
+
run 'rm README'
|
52
|
+
run 'cp config/database.yml config/database.yml.example'
|
53
|
+
run 'rm public/index.html'
|
54
|
+
run 'rm public/favicon.ico'
|
55
|
+
run 'rm public/images/rails.png'
|
56
|
+
run 'touch README'
|
57
|
+
|
58
|
+
# Ignoring files
|
59
|
+
create_file '.gitignore', <<-FILE
|
60
|
+
!gems/bundler
|
61
|
+
!gems/cache
|
62
|
+
*.swp
|
63
|
+
.bundle
|
64
|
+
.DS_Store
|
65
|
+
.yardoc
|
66
|
+
capybara*
|
67
|
+
config/database.yml
|
68
|
+
db/*.sqlite3
|
69
|
+
db/schema.rb
|
70
|
+
doc/api
|
71
|
+
doc/app
|
72
|
+
gems/*
|
73
|
+
log/*.log
|
74
|
+
nbproject/
|
75
|
+
public/system
|
76
|
+
public/uploads/*
|
77
|
+
tmp/**/*
|
78
|
+
FILE
|
79
|
+
|
80
|
+
git :init
|
81
|
+
git :add => '.gitignore'
|
82
|
+
git :commit => '-m "Adding ignore file".'
|
83
|
+
end
|
84
|
+
|
85
|
+
def run_generators_and_fetch_resources
|
86
|
+
with_ssl_fix_for_jquery_rails do
|
87
|
+
generate 'rspec:install'
|
88
|
+
generate 'jquery:install --ui'
|
89
|
+
run "curl -0 https://github.com/malsup/form/raw/master/jquery.form.js > public/javascripts/jquery.form.js "
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def install_log_rotator
|
94
|
+
log_path = '#{Rails.root}/log/#{Rails.env}.log'
|
95
|
+
gsub_file 'config/application.rb', /(< Rails::Application.*)/ , "\\1\n config.logger = Logger.new(\"#{log_path}\", 50, 1048576)"
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_default_root_page
|
99
|
+
generate 'controller Home index'
|
100
|
+
create_file 'app/views/home/index.html.haml', <<-INDEX
|
101
|
+
Welcome, change me, please.
|
102
|
+
INDEX
|
103
|
+
route "root :to => 'home#index'"
|
104
|
+
end
|
105
|
+
|
106
|
+
def install_haml_and_rails
|
107
|
+
gem 'haml-rails'
|
108
|
+
initializer 'haml_sass.rb',
|
109
|
+
'Sass::Plugin.options[:template_location] = File.join([Rails.root, "app", "stylesheets"])'
|
110
|
+
end
|
111
|
+
|
112
|
+
def install_rake_tasks
|
113
|
+
copy_file("bootstrap.rake", 'lib/tasks/bootstrap.rake')
|
114
|
+
end
|
115
|
+
|
116
|
+
def install_simple_form_customizations
|
117
|
+
initializer 'load_simple_form_custom.rb', 'require "simple_form_custom"'
|
118
|
+
copy_file 'simple_form_custom.rb', 'lib/simple_form_custom.rb'
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def with_ssl_fix_for_jquery_rails
|
124
|
+
initializer '002_fixes.rb', <<-FIX
|
125
|
+
# Until the issue with github ssl is fixed.
|
126
|
+
require 'openssl'
|
127
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
128
|
+
FIX
|
129
|
+
yield
|
130
|
+
run 'rm config/initializers/002_fixes.rb'
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
task :adr => 'app:development:reset'
|
2
|
+
task :asr => 'app:staging:reset'
|
3
|
+
task :apr => 'app:production:reset'
|
4
|
+
|
5
|
+
namespace :app do
|
6
|
+
namespace :development do
|
7
|
+
|
8
|
+
desc "Reset development environment"
|
9
|
+
task :reset => [
|
10
|
+
"db:drop:all",
|
11
|
+
"db:create:all",
|
12
|
+
"db:migrate",
|
13
|
+
"app:bootstrap"
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :staging do
|
18
|
+
|
19
|
+
desc "Reset staging environment"
|
20
|
+
task :reset => [
|
21
|
+
"db:drop:all",
|
22
|
+
"db:create:all",
|
23
|
+
"db:migrate",
|
24
|
+
"app:bootstrap"
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
namespace :production do
|
29
|
+
|
30
|
+
desc "Reset production environment"
|
31
|
+
task :reset => [
|
32
|
+
"db:drop:all",
|
33
|
+
"db:create:all",
|
34
|
+
"db:migrate",
|
35
|
+
"app:bootstrap"
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Boostrap the application"
|
40
|
+
task :bootstrap => :environment do
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
en:
|
2
|
+
core:
|
3
|
+
new: "New"
|
4
|
+
back: "Back"
|
5
|
+
edit: "Edit"
|
6
|
+
save: "Save"
|
7
|
+
update: "Update"
|
8
|
+
show: "Show"
|
9
|
+
delete: "Delete"
|
10
|
+
join: "Join"
|
11
|
+
join-button: "Yes, sign me in!"
|
12
|
+
no-button: "No"
|
13
|
+
cancel: "Cancel"
|
14
|
+
confirm: "Are you sure?"
|
15
|
+
home: "Home"
|
16
|
+
logout: "Logout"
|
17
|
+
profile: "Profile"
|
18
|
+
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
es:
|
2
|
+
core:
|
3
|
+
new: "New"
|
4
|
+
back: "Back"
|
5
|
+
edit: "Edit"
|
6
|
+
save: "Save"
|
7
|
+
update: "Update"
|
8
|
+
show: "Show"
|
9
|
+
delete: "Delete"
|
10
|
+
join: "Join"
|
11
|
+
join-button: "Yes, sign me in!"
|
12
|
+
no-button: "No"
|
13
|
+
cancel: "Cancel"
|
14
|
+
confirm: "Are you sure?"
|
15
|
+
home: "Home"
|
16
|
+
logout: "Logout"
|
17
|
+
profile: "Profile"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
development: &non_production_settings
|
2
|
+
app_name: Application
|
3
|
+
admin_email: admin@example.com
|
4
|
+
no_reply_email: no-reply@example.com
|
5
|
+
default_password: "123456"
|
6
|
+
|
7
|
+
test: &test_settings
|
8
|
+
<<: *non_production_settings
|
9
|
+
|
10
|
+
cucumber:
|
11
|
+
<<: *test_settings
|
12
|
+
|
13
|
+
staging:
|
14
|
+
<<: *non_production_settings
|
15
|
+
|
16
|
+
production:
|
17
|
+
<<: *non_production_settings
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module SimpleForm
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
class Base
|
5
|
+
def label_html_options
|
6
|
+
label_options = html_options_for(:label, [input_type, required_class, :label ])
|
7
|
+
label_options[:for] = options[:input_html][:id] if options.key?(:input_html)
|
8
|
+
label_options
|
9
|
+
end
|
10
|
+
def hint_html_options
|
11
|
+
html_options_for(:hint, [:description, :hint])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class StringInput < Base
|
16
|
+
def input_html_classes
|
17
|
+
classes = input_type == :string ? super : super.unshift("string")
|
18
|
+
classes << :text_field
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class NumericInput < Base
|
23
|
+
def input_html_classes
|
24
|
+
super.unshift("text_field")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class BooleanInput < Base
|
29
|
+
end
|
30
|
+
|
31
|
+
class DatePickerInput < Base
|
32
|
+
def input
|
33
|
+
@builder.text_field(attribute_name, input_html_options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class DateTimePickerInput < Base
|
38
|
+
def input
|
39
|
+
@builder.text_field(attribute_name, input_html_options) + "<span class='date_time_picker_button'> </span>".html_safe
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class SubdomainInput < Base
|
44
|
+
def input
|
45
|
+
"http://" + @builder.text_field(attribute_name, input_html_options) + ".#{domain}"
|
46
|
+
end
|
47
|
+
def domain
|
48
|
+
input_options[:domain] || "hhh.com"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module SimpleForm
|
55
|
+
@@wrapper_class = :group
|
56
|
+
@@components = [ :label, :error, :input, :hint ]
|
57
|
+
@@wrapper_error_class = :error
|
58
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
class Core::LayoutGenerator < Rails::Generators::Base
|
4
|
+
attr_accessor :file_name
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
argument :name, :default => 'application'
|
9
|
+
|
10
|
+
def initialize(*args, &block)
|
11
|
+
super
|
12
|
+
@file_name = name
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_layout_file
|
16
|
+
template "views/#{view_language}/layout.html.#{view_language}", "app/views/layouts/#{name}.html.#{view_language}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_sidebar_file
|
20
|
+
template "views/#{view_language}/_sidebar.html.#{view_language}", "app/views/shared/_sidebar.html.#{view_language}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_core_helper
|
24
|
+
template 'core_helper.rb', File.join('app/helpers', "core_helper.rb")
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_buttons
|
28
|
+
directory "images", "public/images"
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_static_files
|
32
|
+
directory "stylesheets", "app/stylesheets/#{file_name}"
|
33
|
+
copy_file 'core.js', "public/javascripts/core.js"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def view_language
|
39
|
+
'haml'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|