codeland-starter 0.0.1

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 (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +56 -0
  8. data/Rakefile +13 -0
  9. data/bin/codeland-starter +5 -0
  10. data/codeland-starter.gemspec +33 -0
  11. data/lib/codeland/starter.rb +50 -0
  12. data/lib/codeland/starter/cli.rb +33 -0
  13. data/lib/codeland/starter/codeland-starter.yml +5 -0
  14. data/lib/codeland/starter/configuration.rb +37 -0
  15. data/lib/codeland/starter/integrations/heroku.rb +87 -0
  16. data/lib/codeland/starter/version.rb +5 -0
  17. data/spec/fixtures/heroku_app.json +30 -0
  18. data/spec/spec_helper.rb +111 -0
  19. data/spec/starter/configuration_spec.rb +64 -0
  20. data/spec/starter/integrations/heroku_spec.rb +177 -0
  21. data/spec/starter/starter_spec.rb +62 -0
  22. data/template/codeland.rb +276 -0
  23. data/template/files/Procfile +1 -0
  24. data/template/files/app/assets/javascripts/flash.js.coffee.erb +11 -0
  25. data/template/files/app/assets/stylesheets/application.scss +18 -0
  26. data/template/files/app/assets/stylesheets/atoms/.keep +0 -0
  27. data/template/files/app/assets/stylesheets/base/_base.scss +0 -0
  28. data/template/files/app/assets/stylesheets/base/_typography.scss +0 -0
  29. data/template/files/app/assets/stylesheets/base/_utility.scss +0 -0
  30. data/template/files/app/assets/stylesheets/base/_variables-colors.scss +3 -0
  31. data/template/files/app/assets/stylesheets/base/_variables.scss +0 -0
  32. data/template/files/app/assets/stylesheets/molecules/_flash.scss +21 -0
  33. data/template/files/app/assets/stylesheets/organisms/_footer.scss +0 -0
  34. data/template/files/app/assets/stylesheets/organisms/_header.scss +0 -0
  35. data/template/files/app/views/layouts/_flash.html.slim +6 -0
  36. data/template/files/app/views/layouts/application.html.slim.erb +19 -0
  37. data/template/files/app/views/partials/_footer.html.slim +0 -0
  38. data/template/files/app/views/partials/_header.html.slim +0 -0
  39. metadata +244 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a0761709a566e84eed90a0bf8b683b2c4efff22
4
+ data.tar.gz: 56715ca2a83973b2080407a3d444ab3e8d3cf59a
5
+ SHA512:
6
+ metadata.gz: 6f8ad127cb38e128bd40e01e5e7fef25503866d1c1391e71defbeb0518dccad782ede7918f8f342457c69fb07a1018b4ffb70ae70cb1d572b099537bf0caa8ce
7
+ data.tar.gz: 7a14a157d8cd0c05ba30c79b0b92ca3bd8d7ff7df0f3b34ac0dca461a6d733c7f13ec7ee637aea532ced01df6aae7660827876ec9a49cce65d26408456aa1842
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.1
6
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codeland-starter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 CODELAND Ltda.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Codeland::Starter
2
+
3
+ [![Code Climate](https://codeclimate.com/github/codelandev/codeland-starter/badges/gpa.svg)](https://codeclimate.com/github/codelandev/codeland-starter) [![Build Status](https://travis-ci.org/codelandev/codeland-starter.svg?branch=master)](https://travis-ci.org/codelandev/codeland-starter) [![Test Coverage](https://codeclimate.com/github/codelandev/codeland-starter/badges/coverage.svg)](https://codeclimate.com/github/codelandev/codeland-starter)
4
+
5
+ Create [Ruby on Rails](http://rubyonrails.org/) projects based on [Codeland's](http://codeland.com.br) template with [integrations](#integrations).
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ $ gem install codeland-starter
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Setup
16
+
17
+ ```sh
18
+ $ codeland-starter install # Will create ~/codeland-starter.yml
19
+ $ vi ~/codeland-starter.yml
20
+ ```
21
+
22
+ The `integrations` section in YAML is an array of the services. Eg:
23
+ ```yaml
24
+ integrations:
25
+ - heroku
26
+ - another-service
27
+ ```
28
+
29
+ ### Create projects
30
+
31
+ ```sh
32
+ $ codeland-starter create ProjectName
33
+ ```
34
+
35
+ ## Integrations
36
+
37
+ ### Heroku
38
+
39
+ ```sh`
40
+ $ heroku plugins:install git@github.com:heroku/heroku-oauth.git
41
+ $ heroku authorizations:create -d "some text"
42
+ ```
43
+ Paste the `Token` in
44
+
45
+ ```yaml
46
+ heroku:
47
+ oauth_token: PASTE-YOUR-TOKEN-HERE
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/codelandev/codeland-starter/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ desc 'Open an irb session preloaded with this library'
5
+ task :console do
6
+ sh 'irb -rubygems -I lib -r codeland/starter.rb'
7
+ end
8
+
9
+ # Default directory to look in is `/specs`
10
+ # Run with `rake spec`
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/ruby
2
+
3
+ require 'codeland/starter/cli'
4
+
5
+ Codeland::Starter::CLI.start(ARGV)
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codeland/starter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'codeland-starter'
8
+ spec.version = Codeland::Starter::VERSION
9
+ spec.authors = ['Sérgio Schnorr Júnior', 'Codeland']
10
+ spec.email = %w(jr.schnorr@gmail.com contato@codeland.com.br)
11
+ spec.summary = 'To create Rails projects with template and integrations'
12
+ spec.homepage = 'https://github.com/codelandev/codeland-starter'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = %w(bin lib)
19
+ spec.bindir = 'bin'
20
+
21
+ spec.add_runtime_dependency 'platform-api'
22
+ spec.add_runtime_dependency 'rails', '> 3.1'
23
+ spec.add_runtime_dependency 'thor', '~> 0.19'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.6'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
28
+ spec.add_development_dependency 'webmock', '~> 1.20.3'
29
+ spec.add_development_dependency 'simplecov', '~> 0.9.1'
30
+ spec.add_development_dependency 'simplecov-console'
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.1'
33
+ end
@@ -0,0 +1,50 @@
1
+ require 'codeland/starter/version'
2
+ require 'codeland/starter/configuration'
3
+ dirname = File.dirname(__FILE__)
4
+ Dir["#{dirname}/starter/integrations/*.rb"].each do |file|
5
+ require file
6
+ end
7
+
8
+ module Codeland
9
+ module Starter
10
+ ROOT_PATH = File.join(File.dirname(__FILE__), '..', '..')
11
+
12
+ class << self
13
+ attr_reader :name, :config
14
+
15
+ def create_project(name, yaml_file)
16
+ @name = name
17
+ @config = Configuration.new(yaml_file)
18
+ create_rails_project
19
+ create_integrations
20
+ end
21
+
22
+ def create_rails_project
23
+ options = [
24
+ '--database=postgresql',
25
+ "--template=#{File.join(ROOT_PATH, 'template', 'codeland.rb')}",
26
+ '--skip-bundle',
27
+ '--skip-test-unit'
28
+ ]
29
+ system("rails new #{name} #{options.join(' ')}")
30
+ Dir.chdir(name)
31
+ end
32
+
33
+ def create_integrations
34
+ config.integrations && config.integrations.each do |integration|
35
+ integration_class_name = integration.capitalize
36
+ if have_integration?(integration_class_name)
37
+ client = Integrations.const_get(integration_class_name).new
38
+ client.perform
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def have_integration?(integration)
46
+ const_defined?(:Integrations) && Integrations.const_defined?(integration)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+ require 'codeland/starter'
2
+ require 'thor'
3
+
4
+ module Codeland
5
+ module Starter
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+
9
+ desc 'create NAME', 'Ask for services to create with given NAME'
10
+ method_option :file, {
11
+ :required => true,
12
+ :default => "~/#{Configuration::DEFAULT_FILENAME}",
13
+ :aliases => :f,
14
+ :type => :string
15
+ }
16
+ def create(name)
17
+ Codeland::Starter.create_project(name, options[:file])
18
+ end
19
+
20
+ desc 'install', "Setup configuration yml to ~/#{Configuration::DEFAULT_FILENAME}"
21
+ def install
22
+ destination = File.join(Dir.home, Configuration::DEFAULT_FILENAME)
23
+ copy_file('codeland-starter.yml', destination)
24
+ end
25
+
26
+ private
27
+
28
+ def self.source_root
29
+ File.dirname(__FILE__)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ integrations:
2
+ - heroku
3
+
4
+ heroku:
5
+ oauth_token: 'YOUR-TOKEN'
@@ -0,0 +1,37 @@
1
+ require 'yaml'
2
+ require 'codeland/starter'
3
+
4
+ module Codeland
5
+ module Starter
6
+ class Configuration
7
+ attr_reader :yaml
8
+
9
+ DEFAULT_FILENAME = 'codeland-starter.yml'
10
+
11
+ def initialize(yaml_file)
12
+ @yaml = if File.exists?(yaml_file)
13
+ YAML.load_file(File.open(yaml_file))
14
+ elsif File.exists?(default_yaml_file)
15
+ YAML.load_file(File.open(default_yaml_file))
16
+ else
17
+ message = 'Please install with `codeland-starter install`'
18
+ raise MissingYAML, message
19
+ end
20
+ end
21
+
22
+ def default_yaml_file
23
+ File.join(Dir.home, DEFAULT_FILENAME)
24
+ end
25
+
26
+ def integrations
27
+ yaml['integrations']
28
+ end
29
+
30
+ def self.[](key)
31
+ Starter.config.yaml[key] if Starter.config
32
+ end
33
+ end
34
+
35
+ class MissingYAML < StandardError; end
36
+ end
37
+ end
@@ -0,0 +1,87 @@
1
+ require 'codeland/starter'
2
+ require 'platform-api'
3
+
4
+ module Codeland
5
+ module Starter
6
+ module Integrations
7
+ class Heroku
8
+ attr_reader :app
9
+
10
+ def initialize
11
+ token = if Configuration['heroku']
12
+ Configuration['heroku']['oauth_token']
13
+ else
14
+ yaml = Starter.config.yaml
15
+ message = "Missing heroku key in #{yaml}"
16
+ missing_config(message)
17
+ end
18
+ @app = {}
19
+ @success = false
20
+ @api = PlatformAPI.connect_oauth(token)
21
+ end
22
+
23
+ def perform
24
+ create
25
+ output
26
+ end
27
+
28
+ def create
29
+ begin
30
+ @app = create_app(Starter.name)
31
+ @success = true
32
+ rescue Excon::Errors::Unauthorized
33
+ yaml = Starter.config.yaml
34
+ missing_config("Please verify the Heroku oauth key in #{yaml}")
35
+ rescue Excon::Errors::UnprocessableEntity
36
+ @app = create_random_app
37
+ @success = true
38
+ ensure
39
+ add_git_remote
40
+ end
41
+ end
42
+
43
+ def output
44
+ if success?
45
+ puts <<-MESSAGE.gsub(/^\s{12}/, '')
46
+ Heroku created with
47
+ URL: #{app['web_url']}
48
+ Git remote: #{app['git_url']}
49
+ MESSAGE
50
+ else
51
+ puts 'heroku failed'
52
+ puts app
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ attr_reader :api
59
+
60
+ def create_random_app
61
+ puts 'Heroku app already in use. Using a random name'
62
+ create_app
63
+ end
64
+
65
+ def create_app(app_name = nil)
66
+ api.app.create({
67
+ :name => app_name,
68
+ :region => 'us',
69
+ :stack => 'cedar'
70
+ })
71
+ end
72
+
73
+ def success?
74
+ @success
75
+ end
76
+
77
+ def missing_config(message)
78
+ raise MissingYAML, message
79
+ end
80
+
81
+ def add_git_remote
82
+ system("git remote add heroku #{app['git_url']}") if success?
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,5 @@
1
+ module Codeland
2
+ module Starter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ {
2
+ "archived_at": "2012-01-01T12:00:00Z",
3
+ "buildpack_provided_description": "Ruby/Rack",
4
+ "build_stack": {
5
+ "id": "01234567-89ab-cdef-0123-456789abcdef",
6
+ "name": "cedar"
7
+ },
8
+ "created_at": "2012-01-01T12:00:00Z",
9
+ "git_url": "git@heroku.com:example.git",
10
+ "id": "01234567-89ab-cdef-0123-456789abcdef",
11
+ "maintenance": false,
12
+ "name": "example",
13
+ "owner": {
14
+ "email": "username@example.com",
15
+ "id": "01234567-89ab-cdef-0123-456789abcdef"
16
+ },
17
+ "region": {
18
+ "id": "01234567-89ab-cdef-0123-456789abcdef",
19
+ "name": "us"
20
+ },
21
+ "released_at": "2012-01-01T12:00:00Z",
22
+ "repo_size": 0,
23
+ "slug_size": 0,
24
+ "stack": {
25
+ "id": "01234567-89ab-cdef-0123-456789abcdef",
26
+ "name": "cedar"
27
+ },
28
+ "updated_at": "2012-01-01T12:00:00Z",
29
+ "web_url": "http://example.herokuapp.com/"
30
+ }