sparkler 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/sparkler CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path(File.join('..', 'lib', 'sparkler', 'generators', 'app_generator'), File.dirname(__FILE__))
4
+ require File.expand_path(File.join('..', 'lib', 'sparkler', 'actions'), File.dirname(__FILE__))
4
5
  require File.expand_path(File.join('..', 'lib', 'sparkler', 'app_builder'), File.dirname(__FILE__))
5
6
 
6
7
  templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
@@ -0,0 +1,13 @@
1
+ module Sparkler
2
+ module Actions
3
+ def replace_in_file(relative_path, find, replace)
4
+ path = File.join(destination_root, relative_path)
5
+ contents = IO.read(path)
6
+ unless contents.gsub!(find, replace)
7
+ raise "#{find.inspect} not found in #{relative_path}"
8
+ end
9
+ File.open(path, "w") { |file| file.write(contents) }
10
+ end
11
+ end
12
+ end
13
+
@@ -1,5 +1,6 @@
1
1
  module Sparkler
2
2
  class AppBuilder < Rails::AppBuilder
3
+ include Sparkler::Actions
3
4
 
4
5
  def remove_public_index
5
6
  remove_file 'public/index.html'
@@ -12,5 +13,106 @@ module Sparkler
12
13
  def setup_staging_environment
13
14
  run 'cp config/environments/production.rb config/environments/staging.rb'
14
15
  end
16
+
17
+ def create_partials_directory
18
+ empty_directory 'app/views/application'
19
+ end
20
+
21
+ def create_shared_flashes
22
+ copy_file '_flashes.html.haml', 'app/views/application/_flashes.html.haml'
23
+ end
24
+
25
+ def create_application_layout
26
+ remove_file 'app/views/layouts/application.html.erb'
27
+ template 'application_layout.html.haml', 'app/views/layouts/application.html.haml', force: true
28
+ end
29
+
30
+ def add_custom_gems
31
+ additions_path = find_in_source_paths 'Gemfile_additions'
32
+ new_gems = File.open(additions_path).read
33
+ inject_into_file 'Gemfile', "\n#{new_gems}", after: /gem 'jquery-rails'/
34
+
35
+ asset_gems = <<-END.gsub(/^ {6}/, '')
36
+ gem 'compass-rails', '~> 1.0.3'
37
+ gem 'zurb-foundation', '~> 3.0.9'
38
+ END
39
+
40
+ inject_into_file 'Gemfile', "\n#{asset_gems}", after: /gem 'uglifier'.*$/
41
+ end
42
+
43
+ def use_postgres_config_template
44
+ template 'database.yml.erb', 'config/database.yml', force: true
45
+ end
46
+
47
+ def setup_local_postgres
48
+ run 'initdb pg'
49
+ end
50
+
51
+ def ignore_local_postgres
52
+ append_file '.git/info/exclude', '/pg/'
53
+ end
54
+
55
+ def create_database
56
+ pid = fork { exec 'postgres', '-D', 'pg' }
57
+ bundle_command 'exec rake db:create'
58
+ Process.kill "INT", pid
59
+ end
60
+
61
+ def setup_gitignore
62
+ gitignore_file = find_in_source_paths('gitignore_additions')
63
+ gitignore = File.open(gitignore_file).read
64
+ append_file '.gitignore', gitignore
65
+ end
66
+
67
+ def init_git
68
+ run 'git init'
69
+ end
70
+
71
+ def copy_miscellaneous_files
72
+ copy_file 'time_formats.rb', 'config/initializers/time_formats.rb'
73
+ copy_file 'Procfile'
74
+ end
75
+
76
+ def setup_high_voltage
77
+ empty_directory 'app/views/pages'
78
+ copy_file 'home.html.haml', 'app/views/pages/home.html.haml'
79
+ route "root to: 'high_voltage/pages#show', id: 'home'"
80
+ end
81
+
82
+ def setup_foundation
83
+ generate 'foundation:install'
84
+ end
85
+
86
+ def add_foundation_to_application
87
+ remove_file 'app/assets/stylesheets/application.css'
88
+ copy_file 'application.css.sass', 'app/assets/stylesheets/application.css.sass'
89
+ end
90
+
91
+ def add_env_from_template
92
+ copy_file 'env', '.env'
93
+ end
94
+
95
+ def remove_routes_comment_lines
96
+ replace_in_file 'config/routes.rb', /Application\.routes\.draw do.*end/m, "Application.routes.draw do\nend"
97
+ end
98
+
99
+ def generate_cucumber
100
+ generate 'cucumber:install', '--rspec', '--capybara'
101
+ copy_file 'cucumber_javascript.rb', 'features/support/javascript.rb'
102
+ end
103
+
104
+ def configure_rspec
105
+ generators_config = <<-RUBY.gsub(/^ {6}/, '')
106
+ config.generators do |generate|
107
+ generate.test_framework :rspec
108
+ generate.helper false
109
+ generate.stylesheets false
110
+ generate.javascript_engine false
111
+ generate.view_specs false
112
+ end
113
+ RUBY
114
+ inject_into_class 'config/application.rb', 'Application', generators_config
115
+ generate 'rspec:install'
116
+ end
15
117
  end
16
118
  end
@@ -3,6 +3,9 @@ require 'rails/generators/rails/app/app_generator'
3
3
 
4
4
  module Sparkler
5
5
  class AppGenerator < Rails::Generators::AppGenerator
6
+ class_option :skip_test_unit, type: :boolean, aliases: '-T', default: true, desc: 'Skip Test::Unit files'
7
+ class_option :database, type: :string, aliases: '-d', default: 'postgresql', desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
8
+ class_option :local_database, type: :boolean, aliases: '--local-database', default: false, desc: "Create a pg folder in the application"
6
9
 
7
10
  def finish_template
8
11
  invoke :sparkler_customization
@@ -10,7 +13,18 @@ module Sparkler
10
13
  end
11
14
 
12
15
  def sparkler_customization
16
+ invoke :customize_gemfile
17
+ invoke :setup_database
13
18
  invoke :remove_useless_files
19
+ invoke :remove_routes_comment_lines
20
+ invoke :setup_staging_environment
21
+ invoke :create_views_and_layouts
22
+ invoke :copy_miscellaneous_files
23
+ invoke :setup_foundation
24
+ invoke :setup_env
25
+ invoke :setup_cucumber
26
+ invoke :setup_rspec
27
+ invoke :setup_git
14
28
  end
15
29
 
16
30
  def remove_useless_files
@@ -18,10 +32,76 @@ module Sparkler
18
32
  build :remove_rails_logo_image
19
33
  end
20
34
 
35
+ def setup_database
36
+ if 'postgresql' == options[:database]
37
+ build :use_postgres_config_template
38
+ build :setup_local_postgres if options[:local_database]
39
+ end
40
+ build :create_database
41
+ end
42
+
21
43
  def setup_staging_environment
22
44
  say 'Setting up the staging environment'
23
45
  build :setup_staging_environment
24
- build :initialize_on_precompile
46
+ end
47
+
48
+ def create_views_and_layouts
49
+ say 'Creating layouts and partials'
50
+ build :create_partials_directory
51
+ build :create_shared_flashes
52
+ build :create_application_layout
53
+
54
+ say 'Setting up High Voltage and a home page'
55
+ build :setup_high_voltage
56
+ end
57
+
58
+ def setup_foundation
59
+ say 'Generating Foundation'
60
+ build :setup_foundation
61
+ build :add_foundation_to_application
62
+ end
63
+
64
+ def customize_gemfile
65
+ say 'Setting up gems and bundling'
66
+ build :add_custom_gems
67
+ bundle_command 'install --binstubs --path vendor'
68
+ bundle_command 'package'
69
+ end
70
+
71
+ def setup_git
72
+ say 'Initalizing git repo'
73
+ build :setup_gitignore
74
+ build :init_git
75
+ build :ignore_local_postgres if options[:local_database]
76
+ end
77
+
78
+ def copy_miscellaneous_files
79
+ say 'Copying miscellaneous support files'
80
+ build :copy_miscellaneous_files
81
+ end
82
+
83
+ def setup_env
84
+ say 'Adding an .env file'
85
+ build :add_env_from_template
86
+ end
87
+
88
+ def setup_cucumber
89
+ say 'Installing and configuring Cucumber'
90
+ build :generate_cucumber
91
+ say "Don't forget to install chromedriver if you haven't already."
92
+ end
93
+
94
+ def setup_rspec
95
+ say 'Configuring Rspec'
96
+ build :configure_rspec
97
+ end
98
+
99
+ def remove_routes_comment_lines
100
+ build :remove_routes_comment_lines
101
+ end
102
+
103
+ def outro
104
+ say 'Congratulations! Your app is ready to go!'
25
105
  end
26
106
 
27
107
  def run_bundle
@@ -1,3 +1,3 @@
1
1
  module Sparkler
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,28 @@
1
+ gem 'thin'
2
+ gem 'haml-rails'
3
+ gem 'high_voltage'
4
+ gem 'rdiscount'
5
+ gem 'airbrake'
6
+
7
+ group :development do
8
+ gem 'heroku'
9
+ gem 'foreman'
10
+ end
11
+
12
+ group :development, :test do
13
+ gem 'rspec-rails', '~> 2.9.0'
14
+ gem 'dotenv'
15
+ end
16
+
17
+ group :test do
18
+ gem 'cucumber-rails', '1.3.0', :require => false
19
+ gem 'factory_girl_rails'
20
+ gem 'database_cleaner'
21
+ gem 'timecop'
22
+ gem 'shoulda-matchers'
23
+ gem 'launchy'
24
+ end
25
+
26
+ group :staging, :production do
27
+ gem 'newrelic_rpm'
28
+ end
@@ -0,0 +1,2 @@
1
+ web: bundle exec thin start -p $PORT
2
+ <% if options[:local_database] %>db: postgres -D pg<% end %>
@@ -0,0 +1,3 @@
1
+ - flash.each do |level, message|
2
+ = content_tag(:div, message, class: "flash #{message}")
3
+
@@ -0,0 +1,18 @@
1
+ @import foundation_and_overrides
2
+
3
+ body
4
+ background-color: darken(#fff, 5)
5
+ margin-top: 1em
6
+
7
+ header, #main, footer
8
+ background-color: #fff
9
+
10
+ header
11
+ @include border-radius(5px 5px 0 0)
12
+
13
+ footer
14
+ @include border-radius(0 0 5px 5px)
15
+ p
16
+ font-size: 80%
17
+ color: #aaa
18
+
@@ -0,0 +1,23 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %meta{charset: "utf-8"}
5
+ %meta{name: "viewport", content: "width=device-width, initial-scale=1.0"}
6
+ = content_for(:head)
7
+ %title= content_for?(:title) ? yield(:title) : "Untitled"
8
+ = stylesheet_link_tag "application"
9
+ = csrf_meta_tags
10
+ %body
11
+ #wrapper.container
12
+ %header.row
13
+ .columns.twelve
14
+ %h1 Header
15
+ #main.row
16
+ .columns.twelve
17
+ = render 'application/flashes'
18
+ = yield
19
+ %footer.row
20
+ .columns.twelve
21
+ %p &copy; #{Date.today.year} Gaslight Software LLC. All Rights Reserved.
22
+ = javascript_include_tag "application"
23
+ = content_for(:javascript)
@@ -0,0 +1,5 @@
1
+ Capybara.register_driver :chrome do |app|
2
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
3
+ end
4
+
5
+ Capybara.javascript_driver = :chrome
@@ -0,0 +1,10 @@
1
+ development: &default
2
+ adapter: postgresql
3
+ database: <%= app_name %>_development
4
+ pool: 5
5
+ timeout: 5000
6
+ min_messages: warning
7
+
8
+ test: &TEST
9
+ <<: *default
10
+ database: <%= app_name %>_test
data/templates/env ADDED
@@ -0,0 +1,2 @@
1
+ PORT=3000
2
+
@@ -0,0 +1,4 @@
1
+
2
+ # Vendor Everything
3
+ /bin/
4
+ /vendor/ruby/
@@ -0,0 +1,5 @@
1
+ - content_for(:title) { 'Welcome' }
2
+ :markdown
3
+ # This is a home page
4
+
5
+ Content is written using Markdown, like Gruber intended.
@@ -0,0 +1,6 @@
1
+ # {
2
+ # :short_date => "%x", # 04/13/10
3
+ # :long_date => "%a, %b %d, %Y" # Tue, Apr 13, 2010
4
+ # }.each do |format_name, format_string|
5
+ # Time::DATE_FORMATS[format_name] = format_string
6
+ # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70293825788640 !ruby/object:Gem::Requirement
16
+ requirement: &70301467704640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.8
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70293825788640
24
+ version_requirements: *70301467704640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70293825786380 !ruby/object:Gem::Requirement
27
+ requirement: &70301451199300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '1.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70293825786380
35
+ version_requirements: *70301451199300
36
36
  description: ''
37
37
  email:
38
38
  - chrism@gaslightsoftware.com
@@ -48,10 +48,22 @@ files:
48
48
  - Rakefile
49
49
  - bin/sparkler
50
50
  - lib/sparkler.rb
51
+ - lib/sparkler/actions.rb
51
52
  - lib/sparkler/app_builder.rb
52
53
  - lib/sparkler/generators/app_generator.rb
53
54
  - lib/sparkler/version.rb
54
55
  - sparkler.gemspec
56
+ - templates/Gemfile_additions
57
+ - templates/Procfile
58
+ - templates/_flashes.html.haml
59
+ - templates/application.css.sass
60
+ - templates/application_layout.html.haml
61
+ - templates/cucumber_javascript.rb
62
+ - templates/database.yml.erb
63
+ - templates/env
64
+ - templates/gitignore_additions
65
+ - templates/home.html.haml
66
+ - templates/time_formats.rb
55
67
  - test/lib/sparkler/version_test.rb
56
68
  - test/test_helper.rb
57
69
  homepage: https://github.com/gaslight/sparkler