learn-generate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +54 -0
  7. data/Rakefile +1 -0
  8. data/bin/learn-generate +43 -0
  9. data/learn-generate.gemspec +23 -0
  10. data/lib/learn_generate/file_finder.rb +19 -0
  11. data/lib/learn_generate/helpers/dot-learn-helper.rb +12 -0
  12. data/lib/learn_generate/helpers/gemfile-helper.rb +48 -0
  13. data/lib/learn_generate/helpers/template-helper.rb +52 -0
  14. data/lib/learn_generate/template_loader.rb +96 -0
  15. data/lib/learn_generate/template_maker.rb +115 -0
  16. data/lib/learn_generate/version.rb +3 -0
  17. data/lib/learn_generate.rb +10 -0
  18. data/lib/templates/activerecord/.gitignore +0 -0
  19. data/lib/templates/activerecord/.rspec +3 -0
  20. data/lib/templates/activerecord/README.md +5 -0
  21. data/lib/templates/activerecord/Rakefile +22 -0
  22. data/lib/templates/activerecord/app/models/sample-class.rb +2 -0
  23. data/lib/templates/activerecord/config/environment.rb +26 -0
  24. data/lib/templates/activerecord/db/migrations/.keep +0 -0
  25. data/lib/templates/activerecord/lib/support/connection_adapter.rb +15 -0
  26. data/lib/templates/activerecord/lib/support/db_registry.rb +4 -0
  27. data/lib/templates/activerecord/spec/spec_helper.rb +21 -0
  28. data/lib/templates/command-line/.gitignore +0 -0
  29. data/lib/templates/command-line/.rspec +3 -0
  30. data/lib/templates/command-line/README.md +5 -0
  31. data/lib/templates/command-line/bin/runner.rb +4 -0
  32. data/lib/templates/command-line/lib/environment.rb +5 -0
  33. data/lib/templates/command-line/lib/lab-name/cli.rb +4 -0
  34. data/lib/templates/command-line/spec/spec_helper.rb +80 -0
  35. data/lib/templates/front-end/.gitignore +0 -0
  36. data/lib/templates/front-end/README.md +5 -0
  37. data/lib/templates/front-end/css/style.css +0 -0
  38. data/lib/templates/front-end/images/.keep +0 -0
  39. data/lib/templates/front-end/index.html +11 -0
  40. data/lib/templates/fundamental-ruby/.gitignore +0 -0
  41. data/lib/templates/fundamental-ruby/.rspec +3 -0
  42. data/lib/templates/fundamental-ruby/README.md +5 -0
  43. data/lib/templates/fundamental-ruby/lib/file.rb +0 -0
  44. data/lib/templates/fundamental-ruby/spec/spec_helper.rb +80 -0
  45. data/lib/templates/js/README.md +5 -0
  46. data/lib/templates/js/css/.keep +0 -0
  47. data/lib/templates/js/images/.keep +0 -0
  48. data/lib/templates/js/index.html +8 -0
  49. data/lib/templates/js/js/file.js +0 -0
  50. data/lib/templates/js/js/jquery-1.8.3.min.js +2 -0
  51. data/lib/templates/js/requires.yml +6 -0
  52. data/lib/templates/js/spec/.keep +0 -0
  53. data/lib/templates/kids/.DS_Store +0 -0
  54. data/lib/templates/kids/.rspec +3 -0
  55. data/lib/templates/kids/README.md +14 -0
  56. data/lib/templates/kids/lib/file.rb +0 -0
  57. data/lib/templates/kids/spec/spec_helper.rb +80 -0
  58. data/lib/templates/rack/.gitignore +0 -0
  59. data/lib/templates/rack/.rspec +3 -0
  60. data/lib/templates/rack/README.md +5 -0
  61. data/lib/templates/rack/app/application.rb +7 -0
  62. data/lib/templates/rack/app/controllers/erb_maker.rb +2 -0
  63. data/lib/templates/rack/config/environment.rb +8 -0
  64. data/lib/templates/rack/config.ru +4 -0
  65. data/lib/templates/rack/lib/templates/my_cool_response.html.erb +5 -0
  66. data/lib/templates/rack/spec/controllers/01_server_port_spec.rb +11 -0
  67. data/lib/templates/rack/spec/spec_helper.rb +12 -0
  68. data/lib/templates/rack/spec/support/an_ok_request.rb +5 -0
  69. data/lib/templates/rake/.gitignore +0 -0
  70. data/lib/templates/rake/.rspec +3 -0
  71. data/lib/templates/rake/README.md +5 -0
  72. data/lib/templates/rake/Rakefile +6 -0
  73. data/lib/templates/rake/bin/console +20 -0
  74. data/lib/templates/rake/config/environment.rb +1 -0
  75. data/lib/templates/rake/lib/file.rb +0 -0
  76. data/lib/templates/rake/spec/rakefile_spec.rb +5 -0
  77. data/lib/templates/rake/spec/spec_helper.rb +9 -0
  78. data/lib/templates/sinatra-classic/.gitignore +0 -0
  79. data/lib/templates/sinatra-classic/.rspec +3 -0
  80. data/lib/templates/sinatra-classic/README.md +5 -0
  81. data/lib/templates/sinatra-classic/Rakefile +9 -0
  82. data/lib/templates/sinatra-classic/app.rb +4 -0
  83. data/lib/templates/sinatra-classic/config/environment.rb +7 -0
  84. data/lib/templates/sinatra-classic/config.ru +3 -0
  85. data/lib/templates/sinatra-classic/models/.keep +0 -0
  86. data/lib/templates/sinatra-classic/public/images/.keep +0 -0
  87. data/lib/templates/sinatra-classic/public/javascripts/.keep +0 -0
  88. data/lib/templates/sinatra-classic/public/stylesheets/.keep +0 -0
  89. data/lib/templates/sinatra-classic/spec/spec_helper.rb +5 -0
  90. data/lib/templates/sinatra-classic/views/.keep +0 -0
  91. data/lib/templates/sinatra-mvc/.gitignore +0 -0
  92. data/lib/templates/sinatra-mvc/.rspec +3 -0
  93. data/lib/templates/sinatra-mvc/Gemfile +15 -0
  94. data/lib/templates/sinatra-mvc/README.md +5 -0
  95. data/lib/templates/sinatra-mvc/Rakefile +10 -0
  96. data/lib/templates/sinatra-mvc/app/controllers/application_controller.rb +5 -0
  97. data/lib/templates/sinatra-mvc/app/models/.keep +0 -0
  98. data/lib/templates/sinatra-mvc/app/views/layout.erb +10 -0
  99. data/lib/templates/sinatra-mvc/config/environment.rb +11 -0
  100. data/lib/templates/sinatra-mvc/config.ru +14 -0
  101. data/lib/templates/sinatra-mvc/db/migrate/.keep +0 -0
  102. data/lib/templates/sinatra-mvc/db/seeds.rb +1 -0
  103. data/lib/templates/sinatra-mvc/public/stylesheets/.keep +0 -0
  104. data/lib/templates/sinatra-mvc/spec/controllers/.keep +0 -0
  105. data/lib/templates/sinatra-mvc/spec/features/.keep +0 -0
  106. data/lib/templates/sinatra-mvc/spec/models/.keep +0 -0
  107. data/lib/templates/sinatra-mvc/spec/spec_helper.rb +33 -0
  108. data/lib/templates/sql/.gitignore +0 -0
  109. data/lib/templates/sql/.rspec +3 -0
  110. data/lib/templates/sql/README.md +5 -0
  111. data/lib/templates/sql/bin/environment.rb +5 -0
  112. data/lib/templates/sql/bin/run.rb +6 -0
  113. data/lib/templates/sql/bin/sql_runner.rb +23 -0
  114. data/lib/templates/sql/lib/sample.sql +0 -0
  115. data/lib/templates/sql/spec/spec_helper.rb +84 -0
  116. data/spec/flatiron-lab-generator_spec.rb +81 -0
  117. data/spec/spec_helper.rb +12 -0
  118. metadata +192 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7cd0170eb73ddeb9d7a50161cc2a887c0962bd3b
4
+ data.tar.gz: 7d985e95eeef7de156b5c87dce9e6e75fd183205
5
+ SHA512:
6
+ metadata.gz: e84575e41b5d07098e3bee1ec72d4e9d4f4560b6deb00935751f29dbce94afdc3d97632551e9b32e6828458ebab7621831fc1a280bac60a65cdbe5eb07904399
7
+ data.tar.gz: f756e2306be30f27087fba1652b3dd091ae581d5c736ac459accfc4d68148d08be055cd54eb4936c38429089c58e68b465e7d550495ddfb65de9e22969cefb22
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,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flatiron-lab-generator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014-2015 The Flatiron School
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,54 @@
1
+ # Flatiron Lab Generator
2
+
3
+ A gem for generating labs in the format/style we use for making labs at the Flatiron School.
4
+
5
+ ## Dependencies
6
+
7
+ Assumes installation of git.
8
+
9
+ ## Installation
10
+
11
+ Visit [http://gems.flatironschool.com/](http://gems.flatironschool.com/)
12
+
13
+ ## Usage
14
+
15
+ `flatiron-lab-generator <lab-type> <lab-name>`
16
+
17
+ ### With git
18
+
19
+ Execute as `flatiron-lab-generator <lab-type> <lab-name> -g` if you want your template to be created with an initialized git repository.
20
+
21
+ ## Lab Types
22
+
23
+ Lab types have been outlined in the [Curriculum Style Guide](https://github.com/learn-co-curriculum/curriculum-style-guide/blob/master/lab-templates.md)
24
+
25
+ These are the Lab Types:
26
+
27
+ * fundamental-ruby
28
+ * command-line
29
+ * SQL
30
+ * activerecord
31
+ * rake
32
+ * rack
33
+ * sinatra-classic
34
+ * sinatra-mvc
35
+ * js
36
+ * front-end
37
+ * kids
38
+
39
+ We have the [flatiron-rails gem](https://github.com/flatiron-school/flatiron-rails) for generating Rails labs.
40
+
41
+ ## Lab Name
42
+
43
+ The lab-name refers to the name of the lab (example: Sinatra-ORM-Halloween).
44
+
45
+ ## Reposit
46
+
47
+ Logan made an awesome gem that creates a remote git repository from the command line. It's called [Reposit](https://github.com/loganhasson/reposit). After installing that and following the setup steps, run `reposit <lab name> -o learn-co-curriculum`.
48
+
49
+ ## Contributing
50
+
51
+ 1. Clone
52
+ 2. Checkout a new feature branch
53
+ 3. Be sure to run the tests
54
+ 4. Open PR
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'learn_generate'
4
+
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.on('--list', 'List known templates') do |l|
10
+ options[:list] = true
11
+ end
12
+
13
+ opts.on('--internet', 'Perform actions with an internet connection') do |i|
14
+ options[:internet] = true
15
+ end
16
+ end.parse!
17
+
18
+ template_loader = LearnGenerate::TemplateLoader.new(options[:internet])
19
+ known_templates = template_loader.templates
20
+ templates_list = template_loader.printable_list
21
+
22
+ my_banner = <<-EOS
23
+
24
+ Usage: learn generate <lab-name> -t <template-name>
25
+
26
+ Available templates:
27
+
28
+ #{templates_list}
29
+ EOS
30
+
31
+ if options[:list]
32
+ puts <<-EOS
33
+ Available templates:
34
+
35
+ #{templates_list}
36
+ EOS
37
+ elsif !ARGV[0] || !ARGV[1]
38
+ puts my_banner
39
+ elsif !known_templates.include?(ARGV[0])
40
+ puts my_banner
41
+ else
42
+ LearnGenerate::TemplateMaker.run(ARGV[0], ARGV[1])
43
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'learn_generate/version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "learn-generate"
8
+ spec.version = LearnGenerate::VERSION
9
+ spec.authors = ["Flatiron School"]
10
+ spec.email = ["learn@flatironschool.com"]
11
+ spec.summary = %q{A lab generator}
12
+ spec.description = %q{Generates labs for Learn.co based on a set of lab templates}
13
+ spec.homepage = "https://learn.co"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "bin"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,19 @@
1
+ module LearnGenerate
2
+ class FileFinder
3
+ def self.location_to_dir(dir_name)
4
+ new.location_to_dir(dir_name)
5
+ end
6
+
7
+ def location_to_dir(dir_name)
8
+ File.join(File.dirname(File.expand_path(__FILE__)), "#{dir_name}")
9
+ end
10
+
11
+ def self.location_to_file(file_name)
12
+ new.location_to_file(file_name)
13
+ end
14
+
15
+ def location_to_file(file_name)
16
+ File.join(File.dirname(File.expand_path(__FILE__)))
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module LearnGenerate
2
+ module Helpers
3
+ module DotLearnHelper
4
+ def build_dot_learn
5
+ File.open('.learn', 'a') do |f|
6
+ f << "languages:
7
+ tags:"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ module LearnGenerate
2
+ module Helpers
3
+ module GemfileHelper
4
+ def edit_mvc_gemfile
5
+ File.open("Gemfile", 'a') do |f|
6
+ f << "\ngem 'sinatra'
7
+ gem 'activerecord', :require => 'active_record'
8
+ gem 'sinatra-activerecord', :require => 'sinatra/activerecord'
9
+ gem 'rake'
10
+ gem 'require_all'
11
+ gem 'sqlite3'
12
+ gem 'thin'
13
+ gem 'shotgun'
14
+ gem 'pry'
15
+ \ngroup :test do
16
+ gem 'rspec'
17
+ gem 'capybara'
18
+ gem 'rack-test'
19
+ gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git'
20
+ end"
21
+ end
22
+ end
23
+
24
+ def edit_classic_gemfile
25
+ File.open("Gemfile", 'a') do |f|
26
+ f << "\ngem 'sinatra'
27
+ gem 'rake'
28
+ gem 'thin'
29
+ gem 'shotgun'
30
+ gem 'pry'
31
+ gem 'require_all'
32
+ \ngroup :test do
33
+ gem 'rspec'
34
+ gem 'capybara'
35
+ gem 'rack-test'
36
+ end"
37
+ end
38
+ end
39
+
40
+ def edit_gemfile
41
+ File.open("Gemfile", 'a') do |f|
42
+ f << "\ngem 'rspec'
43
+ gem 'pry'"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,52 @@
1
+ module LearnGenerate
2
+ module Helpers
3
+ module TemplateHelper
4
+ def fundamental_helper
5
+ change_filename('lib/', 'file.rb', 'rb')
6
+ edit_file('spec/spec_helper.rb', formatted_lab_name)
7
+ edit_gemfile
8
+ end
9
+
10
+ def command_line_helper
11
+ edit_file("bin/runner.rb", formatted_lab_name)
12
+ edit_file("spec/spec_helper.rb", formatted_lab_name)
13
+ edit_file("lib/environment.rb", formatted_lab_name)
14
+ FileUtils.mv("lib/lab-name", "lib/#{lab_name}")
15
+ edit_gemfile
16
+ end
17
+
18
+ def sql_helper
19
+ change_filename('lib/', 'sample.sql', 'sql')
20
+ end
21
+
22
+ def rake_helper
23
+ change_filename('lib/', 'file.rb', 'rb')
24
+ edit_file("config/environment.rb", formatted_lab_name)
25
+ edit_gemfile
26
+ end
27
+
28
+ def sinatra_mvc_helper
29
+ edit_mvc_gemfile
30
+ end
31
+
32
+ def sinatra_classic_helper
33
+ edit_classic_gemfile
34
+ end
35
+
36
+ def js_helper
37
+ change_filename('js/', 'file.js', 'js')
38
+ end
39
+
40
+ def fe_helper
41
+ edit_file('index.html', formatted_name)
42
+ end
43
+
44
+ def kids_helper
45
+ change_filename('lib/', 'file.rb', 'rb')
46
+ edit_file('spec/spec_helper.rb', formatted_lab_name)
47
+ edit_spec("spec/#{formatted_lab_name}_spec.rb")
48
+ edit_gemfile
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,96 @@
1
+ module LearnGenerate
2
+ class TemplateLoader
3
+ attr_reader :internet, :local_path, :local_dir
4
+ attr_accessor :templates
5
+
6
+ BASE_TEMPLATES = [
7
+ 'fundamental-ruby',
8
+ 'command-line',
9
+ 'sql',
10
+ 'activerecord',
11
+ 'rake',
12
+ 'erb-static-site',
13
+ 'rack',
14
+ 'sinatra-classic',
15
+ 'sinatra-mvc',
16
+ 'js',
17
+ 'front-end',
18
+ 'kids'
19
+ ]
20
+
21
+ def initialize(internet)
22
+ @internet = internet
23
+ @local_dir = File.expand_path('~/.learn-generate')
24
+ @local_path = File.expand_path('~/.learn-generate/templates')
25
+
26
+ set_templates
27
+ end
28
+
29
+ def printable_list
30
+ templates.map.with_index do |template, index|
31
+ "#{index+1}. #{template}"
32
+ end.join("\n ")
33
+ end
34
+
35
+ private
36
+
37
+ def set_templates
38
+ if internet
39
+ if has_local_copy?
40
+ get_and_update_templates
41
+ else
42
+ prep_local_copy
43
+ get_and_update_templates(silent: true)
44
+ end
45
+ elsif has_local_copy?
46
+ update_local_templates
47
+ else
48
+ set_base_templates
49
+ end
50
+ end
51
+
52
+ def prep_local_copy
53
+ create_local_dir
54
+ clone_templates_repo
55
+ end
56
+
57
+ def create_local_dir
58
+ FileUtils.mkdir_p(local_dir)
59
+ end
60
+
61
+ def clone_templates_repo
62
+ puts 'Pulling list of known templates...'
63
+ system("cd #{local_dir} && git clone https://github.com/learn-co-curriculum/learn-generate-templates.git templates")
64
+ end
65
+
66
+ def get_and_update_templates(silent: false)
67
+ get_latest_templates(silent: silent)
68
+ update_local_templates
69
+ end
70
+
71
+ def get_latest_templates(silent: false)
72
+ puts 'Updating templates...' if !silent
73
+ system("cd #{local_path} && git pull --rebase --quiet")
74
+ end
75
+
76
+ def update_local_templates
77
+ self.templates = Dir.entries("#{local_path}/templates").reject {|f| f.start_with?('.') || !File.directory?("#{local_path}/templates/#{f}")}
78
+ end
79
+
80
+ def set_base_templates
81
+ self.templates = BASE_TEMPLATES
82
+ end
83
+
84
+ def has_local_copy?
85
+ has_templates_dir? && templates_dir_is_git_repo?
86
+ end
87
+
88
+ def has_templates_dir?
89
+ File.exists?(local_path) && File.directory?(local_path)
90
+ end
91
+
92
+ def templates_dir_is_git_repo?
93
+ File.exists?("#{local_path}/.git") && File.directory?("#{local_path}/.git")
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,115 @@
1
+ module LearnGenerate
2
+ class TemplateMaker
3
+ include LearnGenerate::Helpers::TemplateHelper
4
+ include LearnGenerate::Helpers::GemfileHelper
5
+ include LearnGenerate::Helpers::DotLearnHelper
6
+
7
+ attr_reader :template_type, :lab_name, :has_templates_dir, :full_templates_path
8
+
9
+ def initialize(template_type, lab_name)
10
+ @template_type = template_type
11
+ @lab_name = lab_name
12
+ templates_path = File.expand_path('~/.learn-generate/templates')
13
+ templates_git_path = File.expand_path('~/.learn-generate/templates/.git')
14
+ @has_templates_dir = File.exists?(templates_path) && File.directory?(templates_path) && File.exists?(templates_git_path) && File.directory?(templates_git_path)
15
+ @full_templates_path = templates_path + '/templates'
16
+ end
17
+
18
+ def self.run(template_type, lab_name)
19
+ new(template_type, lab_name).create
20
+ end
21
+
22
+ def create
23
+ copy
24
+ name_lab
25
+ FileUtils.cd("#{lab_name}") do
26
+ touch_spec unless template_type == "js" || template_type == "sinatra-mvc" || template_type == "front-end"
27
+ touch_dot_learn
28
+ build_dot_learn
29
+ git_init
30
+ bundle_init unless template_type == "js" || template_type == "front-end"
31
+ edit_readme
32
+ fundamental_helper if template_type == "fundamental-ruby"
33
+ command_line_helper if template_type == "command-line"
34
+ sql_helper if template_type == "SQL"
35
+ rake_helper if template_type == "rake"
36
+ sinatra_mvc_helper if template_type == "sinatra-mvc"
37
+ sinatra_classic_helper if template_type == "sinatra-classic"
38
+ js_helper if template_type == "js"
39
+ fe_helper if template_type == "front-end"
40
+ kids_helper if template_type == "kids"
41
+ end
42
+ success_message
43
+ end
44
+
45
+ def copy
46
+ if has_templates_dir
47
+ FileUtils.cp_r("#{full_templates_path}/#{template_type}", FileUtils.pwd)
48
+ else
49
+ FileUtils.cp_r(LearnGenerate::FileFinder.location_to_dir("../templates/#{template_type}"), FileUtils.pwd)
50
+ end
51
+ end
52
+
53
+ def name_lab
54
+ FileUtils.mv(template_type, lab_name)
55
+ end
56
+
57
+ def git_init
58
+ `git init`
59
+ end
60
+
61
+ def edit_readme
62
+ File.open("README.md", 'a') do |f|
63
+ f << "\n# #{formatted_name}"
64
+ end
65
+ end
66
+
67
+ def formatted_name
68
+ lab_name.gsub('-', ' ').split.map(&:capitalize).join(' ')
69
+ end
70
+
71
+ def formatted_lab_name
72
+ lab_name.gsub('-', '_')
73
+ end
74
+
75
+ def bundle_init
76
+ `bundle init`
77
+ end
78
+
79
+ def touch_spec
80
+ FileUtils.cd("spec/") do
81
+ `touch #{formatted_lab_name}_spec.rb`
82
+ end
83
+ end
84
+
85
+ def touch_dot_learn
86
+ `touch .learn`
87
+ end
88
+
89
+ def change_filename(path, filename, extension)
90
+ FileUtils.cd(path) do
91
+ File.rename(filename, "#{formatted_lab_name}.#{extension}")
92
+ end
93
+ end
94
+
95
+ def edit_file(file, text)
96
+ new_rr = IO.read(file) % { file_name: text }
97
+ File.open(file, 'w') { |f| f.write(new_rr) }
98
+ end
99
+
100
+ def edit_spec(file)
101
+ File.open(file, 'w') { |f| f.write("require_relative './spec_helper'") }
102
+ end
103
+
104
+ def success_message
105
+ puts "\n#{formatted_name} Lab successfully created in #{FileUtils.pwd}\n"
106
+ FileUtils.cd("#{lab_name}") do
107
+ tree_output = `which tree 2>/dev/null`
108
+
109
+ if !tree_output.empty?
110
+ puts "#{`tree`}"
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,3 @@
1
+ module LearnGenerate
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'fileutils'
2
+ require 'optparse'
3
+
4
+ require 'learn_generate/version.rb'
5
+ require 'learn_generate/helpers/template-helper'
6
+ require 'learn_generate/helpers/gemfile-helper'
7
+ require 'learn_generate/helpers/dot-learn-helper'
8
+ require 'learn_generate/file_finder'
9
+ require 'learn_generate/template_loader'
10
+ require 'learn_generate/template_maker'
File without changes
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ ---
2
+ tags:
3
+ languages:
4
+ resources:
5
+ ---
@@ -0,0 +1,22 @@
1
+ task :environment do
2
+ ENV["ACTIVE_RECORD_ENV"] ||= "development"
3
+ require_relative './config/environment'
4
+ end
5
+
6
+ namespace :db do
7
+ task :migrate => :environment do
8
+ DB.tables.each do |table|
9
+ DB.execute("DROP TABLE #{table}")
10
+ end
11
+
12
+ Dir[File.join(File.dirname(__FILE__), "db/migrations", "*.rb")].each do |f|
13
+ require f
14
+ migration = Kernel.const_get(f.split("/").last.split(".rb").first.gsub(/\d+/, "").split("_").collect{|w| w.strip.capitalize}.join())
15
+ migration.migrate(:up)
16
+ end
17
+ end
18
+ end
19
+
20
+ task :console => "db:migrate" do
21
+ Pry.start
22
+ end
@@ -0,0 +1,2 @@
1
+ class NameOfClass < ActiveRecord::Base
2
+ end
@@ -0,0 +1,26 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+
4
+ require 'rake'
5
+ require 'active_record'
6
+ require 'yaml/store'
7
+ require 'ostruct'
8
+
9
+ DBNAME = "set_db_name"
10
+
11
+ Dir[File.join(File.dirname(__FILE__), "../app/models", "*.rb")].each {|f| require f}
12
+ Dir[File.join(File.dirname(__FILE__), "../lib/support", "*.rb")].each {|f| require f}
13
+
14
+ DBRegistry[ENV["ACTIVE_RECORD_ENV"]].connect!
15
+ DB = ActiveRecord::Base.connection
16
+
17
+ if ENV["ACTIVE_RECORD_ENV"] == "test"
18
+ ActiveRecord::Migration.verbose = false
19
+ end
20
+
21
+ RAKE_APP ||= begin
22
+ app = Rake.application
23
+ app.init
24
+ app.load_rakefile
25
+ app
26
+ end
File without changes
@@ -0,0 +1,15 @@
1
+ class ConnectionAdapter
2
+ attr_reader :adapter, :database
3
+
4
+ def initialize(database, adapter="sqlite3")
5
+ @adapter = adapter
6
+ @database = database
7
+ end
8
+
9
+ def connect!
10
+ ActiveRecord::Base.establish_connection(
11
+ :adapter => self.adapter,
12
+ :database => self.database
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ DBRegistry ||= OpenStruct.new(test: ConnectionAdapter.new("db/#{DBNAME}-test.db"),
2
+ development: ConnectionAdapter.new("db/#{DBNAME}-development.db"),
3
+ production: ConnectionAdapter.new("db/#{DBNAME}-production.db")
4
+ )
@@ -0,0 +1,21 @@
1
+ ENV["ACTIVE_RECORD_ENV"] = "test"
2
+
3
+ require_relative '../config/environment'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.before do
8
+ run_rake_task('db:migrate')
9
+ end
10
+ end
11
+
12
+ def run_rake_task(task)
13
+ RAKE_APP[task].invoke
14
+ if task == 'db:migrate'
15
+ RAKE_APP[task].reenable
16
+ end
17
+ end
18
+
19
+ def __
20
+ raise "Replace __ with test code."
21
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ ---
2
+ tags:
3
+ languages:
4
+ resources:
5
+ ---