cuba_genie 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54d1c87e824a8b6c3d574ce43e49e72202d75429
4
+ data.tar.gz: feae045ff5a7de6c36d1086aa4a1b8dac4add158
5
+ SHA512:
6
+ metadata.gz: f77ff20643e4118e5d0b2fe6d51befb64a26c495e914466c3d31e0fedbdaeba5a5141f4625c13e969b3bbc4962d14cd44ce5c9e8d0350da348c3ae99c8362c93
7
+ data.tar.gz: 8a76e92b0e00848dc4a2f771d97c64a0059455c9c9afe66b4458f99205511b33e4cd7a26eaa626414f74f37087f78347169b565e717f0b9151dc19a85d47f4d6
@@ -0,0 +1,135 @@
1
+
2
+ # Created by https://www.gitignore.io/api/rubymine,ruby,sublimetext,textmate,vim
3
+
4
+ ### RubyMine ###
5
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
6
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7
+
8
+ # User-specific stuff:
9
+ .idea/workspace.xml
10
+ .idea/tasks.xml
11
+ .idea/dictionaries
12
+ .idea/vcs.xml
13
+ .idea/jsLibraryMappings.xml
14
+
15
+ # Sensitive or high-churn files:
16
+ .idea/dataSources.ids
17
+ .idea/dataSources.xml
18
+ .idea/dataSources.local.xml
19
+ .idea/sqlDataSources.xml
20
+ .idea/dynamic.xml
21
+ .idea/uiDesigner.xml
22
+
23
+ # Gradle:
24
+ .idea/gradle.xml
25
+ .idea/libraries
26
+
27
+ # Mongo Explorer plugin:
28
+ .idea/mongoSettings.xml
29
+
30
+ ## File-based project format:
31
+ *.iws
32
+
33
+ ## Plugin-specific files:
34
+
35
+ # IntelliJ
36
+ /out/
37
+
38
+ # mpeltonen/sbt-idea plugin
39
+ .idea_modules/
40
+
41
+ # JIRA plugin
42
+ atlassian-ide-plugin.xml
43
+
44
+ # Crashlytics plugin (for Android Studio and IntelliJ)
45
+ com_crashlytics_export_strings.xml
46
+ crashlytics.properties
47
+ crashlytics-build.properties
48
+ fabric.properties
49
+
50
+
51
+ ### Ruby ###
52
+ *.gem
53
+ *.rbc
54
+ /.config
55
+ /coverage/
56
+ /InstalledFiles
57
+ /pkg/
58
+ /spec/reports/
59
+ /spec/examples.txt
60
+ /test/tmp/
61
+ /test/version_tmp/
62
+ /tmp/
63
+
64
+ ## Specific to RubyMotion:
65
+ .dat*
66
+ .repl_history
67
+ build/
68
+ *.bridgesupport
69
+ build-iPhoneOS/
70
+ build-iPhoneSimulator/
71
+
72
+ ## Specific to RubyMotion (use of CocoaPods):
73
+ #
74
+ # We recommend against adding the Pods directory to your .gitignore. However
75
+ # you should judge for yourself, the pros and cons are mentioned at:
76
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
77
+ #
78
+ # vendor/Pods/
79
+
80
+ ## Documentation cache and generated files:
81
+ /.yardoc/
82
+ /_yardoc/
83
+ /doc/
84
+ /rdoc/
85
+
86
+ ## Environment normalization:
87
+ /.bundle/
88
+ /vendor/bundle
89
+ /lib/bundler/man/
90
+
91
+ # for a library or gem, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ Gemfile.lock
94
+ .ruby-version
95
+ .ruby-gemset
96
+
97
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
98
+ .rvmrc
99
+
100
+
101
+ ### SublimeText ###
102
+ # cache files for sublime text
103
+ *.tmlanguage.cache
104
+ *.tmPreferences.cache
105
+ *.stTheme.cache
106
+
107
+ # workspace files are user-specific
108
+ *.sublime-workspace
109
+
110
+ # project files should be checked into the repository, unless a significant
111
+ # proportion of contributors will probably not be using SublimeText
112
+ # *.sublime-project
113
+
114
+ # sftp configuration file
115
+ sftp-config.json
116
+
117
+
118
+ ### TextMate ###
119
+ *.tmproj
120
+ *.tmproject
121
+ tmtags
122
+
123
+
124
+ ### Vim ###
125
+ # swap
126
+ [._]*.s[a-w][a-z]
127
+ [._]s[a-w][a-z]
128
+ # session
129
+ Session.vim
130
+ # temporary
131
+ .netrwhist
132
+ *~
133
+ # auto-generated tag files
134
+ tags
135
+
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cuba_genie.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Fred Heath
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ # CubaGenie
2
+
3
+ CubaGenie is a generator gem that sets up all the infrastructure you need in order to be immediately productive with the [Cuba](http://cuba.is/) web application. CubaGenie creates a skeleton Cuba app, configured to your preferences.
4
+
5
+ ## Why use it?
6
+
7
+ [Cuba](http://cuba.is/) is a wonderful DSL that allows us to create simple web-apps quickly and easily. However, for more complex apps we would need to add extra functionality and components to the basic Cuba setup, things like view templates, data stores, static file serving, our favourite JS or CSS framework and so on. This can be a time-consuming task and it's not always obvious how to get everything working together. CubaGenie takes away the hassle by creating everything you need in one fell, quick swoop.
8
+
9
+ ## What does it create?
10
+ 1. A basic Cuba application ready to be ran (config, app-file and Gemfile)
11
+ 2. Ruby version management support files (.ruby-version and .ruby-gemset)
12
+ 3. Standard view templates (layout and home)
13
+ 4. A Minitest setup and basic functional test template (optional)
14
+ 5. A Capybara setup and basic acceptance test template (optional)
15
+ 6. A Rakefile with basic test tasks (optional)
16
+ 6. A Twitter Bootstrap installation, hooked into the view templates (optional)
17
+
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'cuba_genie'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install cuba_genie
34
+
35
+ ## Usage
36
+
37
+ In your shell, cd into your work directory and type:
38
+
39
+ ```shell
40
+ cuba_genie new <your_app_name>
41
+ ```
42
+
43
+ Then simply keep answering the questions CubaGenie asks you.
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `rake test` to run the tests. You can also run `rake console` for an interactive prompt that will allow you to experiment.
48
+
49
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Roadmap
52
+
53
+ * Add RSpec support
54
+ * Add choice of templating engine, e.g. erb, haml, slim, etc.
55
+ * Add Redis support
56
+ * Add relational DB support (possibly through an ORM)
57
+ * Create generator commands for test, model and view templates
58
+ * Add support for user authentication
59
+
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork the repository
64
+ 2. Create your feature branch (git checkout -b my-new-feature)
65
+ 3. Commit your changes (git commit -am 'Add some feature')
66
+ 4. Push to the branch (git push origin my-new-feature)
67
+ 5. Create a merge request (https://gitlab.com/<user-name>/cuba-genie/merge_requests)
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :console do
11
+ exec "irb -r cuba_genie -I ./lib"
12
+ end
13
+
14
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cuba_genie/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cuba_genie"
8
+ spec.version = CubaGenie::VERSION
9
+ spec.authors = ["Fred Heath"]
10
+ spec.email = ["fred_h@bootstrap.me.uk"]
11
+
12
+ spec.summary = %q{CubaGenie is a generator gem that sets up all the infrastructure you need in order to be immediately productive with the Cuba web development DSL }
13
+ spec.description = %q{CubaGenie creates a skeleton Cuba app, configured to your preferences, which may include view templates, test templates, CSS framework and many more.}
14
+ spec.homepage = "https://gitlab.com/RedFred7/cuba-genie"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.8"
25
+ spec.add_development_dependency 'minitest-reporters', '~> 1.0'
26
+ spec.add_development_dependency "fakefs"
27
+ spec.add_development_dependency "m"
28
+ spec.add_development_dependency "pry-byebug"
29
+ spec.add_development_dependency "pry-stack_explorer"
30
+ spec.add_dependency "thor"
31
+ spec.add_dependency "rubyzip"
32
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cuba_genie"
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
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cuba_genie'
4
+
5
+ CubaGenie::MyCLI.start(ARGV)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,105 @@
1
+ require "cuba_genie/version"
2
+ require "cuba_genie/content"
3
+ require "cuba_genie/content_helpers"
4
+
5
+ require 'thor'
6
+ require_relative 'cuba_genie/command_list'
7
+ require_relative 'cuba_genie/cuba_setup'
8
+ require_relative 'cuba_genie/minitest_setup'
9
+ require_relative 'cuba_genie/views_setup'
10
+
11
+ module CubaGenie
12
+
13
+ POSITIVE_RESPONSES = %w(y Y Yes yes t true)
14
+ NEGATIVE_RESPONSES = %w(n N No no f false)
15
+
16
+
17
+ class MyCLI < Thor
18
+ include Content
19
+
20
+ desc "new PROJECT", "create project NAME"
21
+ def new(project_name)
22
+ @cmds = CommandList.new
23
+ puts "your project name is '#{project_name}'"
24
+ minitest = want_minitest?
25
+ reporter = (minitest ? choose_reporter : 'n')
26
+ capybara = (minitest ? want_capybara? : false)
27
+ @cmds.add_command CubaSetup.new(project_name, minitest, capybara)
28
+ @cmds.add_command ViewsSetup.new(project_name, choose_bootstrap_version)
29
+ @cmds.add_command MinitestSetup.new(project_name, reporter, capybara) if minitest
30
+ puts closing_message(project_name) if @cmds.execute
31
+ end
32
+
33
+ private
34
+ def want_minitest?
35
+ puts "Would you like to setup Minitest for your project?"
36
+ ask_for_yes_no_response
37
+ end
38
+
39
+ def want_capybara?
40
+ puts "Would you like to create acceptance (Capybara) tests for your project?"
41
+ ask_for_yes_no_response
42
+ end
43
+
44
+ def choose_reporter
45
+ puts "Choose a Minitest output format (reporter):"
46
+ MINITEST_REPORTERS.each_with_index do |reporter, idx|
47
+ puts "#{idx+1}: #{reporter.keys.first.to_s.extend(ContentHelpers).titlecase} (#{reporter.values.first})"
48
+ end
49
+ response = ask_for_numeric_reponse (1..8)
50
+ puts ""
51
+
52
+ MINITEST_REPORTERS[response.to_i - 1].keys.first.to_s.extend(ContentHelpers).titlecase
53
+ end
54
+
55
+ def choose_bootstrap_version
56
+ puts "Choose which version of Twitter Bootstrap you want to use:"
57
+ (["Don't install Bootstrap"] + ALLOWED_BOOTSTRAP_VERSIONS).each_with_index do |opt, idx|
58
+ puts "#{idx+1}: #{opt}"
59
+ end
60
+ response = ask_for_numeric_reponse (1..5)
61
+ puts ""
62
+
63
+ (response.to_i == 1) ? 'n' : ALLOWED_BOOTSTRAP_VERSIONS[response.to_i - 2]
64
+ end
65
+
66
+ private
67
+
68
+ def ask_for_yes_no_response
69
+ response = STDIN.gets.chomp
70
+ while !(POSITIVE_RESPONSES + NEGATIVE_RESPONSES).include? response
71
+ puts "Enter y or n"
72
+ response = STDIN.gets.chomp
73
+ end
74
+ puts ""
75
+ POSITIVE_RESPONSES.include? response
76
+ end
77
+
78
+
79
+ # Prompts the user for a numeric input, within a valid range
80
+ #
81
+ # @param valid_range [String] captured STDIN
82
+ #
83
+ # @return [Fixnum] an integer within the valid range
84
+ #
85
+ # @note character 0 cannot be used as a range value. The reason is that
86
+ # #to_i will convert any non-numberic character to 0, which the method will
87
+ # then wrongly interpret as a valid character
88
+ #
89
+ def ask_for_numeric_reponse(valid_range)
90
+ response = STDIN.gets.chomp.to_i
91
+ while !valid_range.cover? response
92
+ puts "Enter a number between #{valid_range.first}-#{valid_range.last}"
93
+ response = STDIN.gets.chomp.to_i
94
+ end
95
+ puts ""
96
+ response
97
+ end
98
+
99
+ def closing_message(project_name)
100
+ "\nYour #{project_name} Cuba app is now set up and ready to go! To start the app, cd into #{project_name} directory, run 'bundle install' and then 'rackup'. You can then see your app running on 'http://localhost:9292'."
101
+ end
102
+
103
+
104
+ end #class
105
+ end #module
@@ -0,0 +1,45 @@
1
+ # Implements the Command pattern. Responsible for executing a command list and invoking rollback on any errors
2
+ #
3
+ class CommandList
4
+
5
+ def initialize
6
+ @commands = []
7
+ end
8
+
9
+ def add_command(cmd)
10
+ @commands << cmd
11
+ end
12
+
13
+ def length
14
+ @commands.size
15
+ end
16
+
17
+ def execute
18
+ res = true
19
+ @commands.each_with_index do |cmd, idx|
20
+ unless cmd.execute
21
+ puts "ERROR: #{cmd.error}"
22
+ unexecute(idx)
23
+ res = false
24
+ break
25
+ end
26
+ puts cmd.description unless ENV['RACK_ENV'] == 'test'
27
+ end
28
+ res
29
+ end
30
+
31
+
32
+ def description
33
+ description = ''
34
+ @commands.each { |cmd| description += cmd.description + "\n" }
35
+ description
36
+ end
37
+
38
+ private
39
+ def unexecute(idx)
40
+ @commands.slice(0, idx + 1).reverse_each(&:unexecute)
41
+ end
42
+
43
+ alias_method :size, :length
44
+
45
+ end #module
@@ -0,0 +1,158 @@
1
+ module Content
2
+
3
+
4
+ APP_FILE_CONTENT = %Q(
5
+ require "cuba"
6
+ require "mote"
7
+ require "mote/render"
8
+
9
+ Cuba.plugin(Mote::Render)
10
+
11
+ Cuba.use Rack::Static,
12
+ root: "public",
13
+ urls: ["/css","/js", "/fonts"]
14
+
15
+ Cuba.define do
16
+ on root do
17
+ res.write view("home", {title: "Cuba Genie"})
18
+ end
19
+ end
20
+ )
21
+
22
+
23
+ RACK_FILE_CONTENT = %Q(
24
+ require "./%s"
25
+
26
+ run(Cuba)
27
+ )
28
+
29
+
30
+
31
+ TEST_HELPER_CONTENT_CORE = %Q(
32
+ ENV['RACK_ENV'] = 'test'
33
+ require 'minitest/autorun'
34
+ require 'rack/test'
35
+ require 'minitest/reporters'
36
+ Minitest::Reporters.use! [ Minitest::Reporters::%sReporter.new ]
37
+ %s
38
+
39
+ require_relative '../%s'
40
+
41
+
42
+ class RackTest < MiniTest::Test
43
+
44
+ include Rack::Test::Methods
45
+
46
+ def app
47
+ Cuba
48
+ end
49
+ end
50
+ )
51
+
52
+ TEST_HELPER_CONTENT_CAPYBARA = %Q(
53
+ Capybara.configure do |config|
54
+ config.run_server = false
55
+ config.default_driver = :selenium
56
+ config.app_host = 'http://localhost:9292'
57
+ end
58
+
59
+ class AcceptanceTest < Minitest::Capybara::Test
60
+ end
61
+ )
62
+
63
+
64
+ MINITEST_REPORTERS = [
65
+ { default: 'Redgreen-capable version of standard Minitest reporter'},
66
+ { spec: 'Turn-like output that reads like a spec'},
67
+ { progress: 'Fuubar-like output with a progress bar'},
68
+ { rubyMate: 'Simple reporter designed for RubyMate'},
69
+ { rubyMine: 'Reporter designed for RubyMine IDE and TeamCity CI server'},
70
+ { jUnit: 'JUnit test reporter designed for JetBrains TeamCity'},
71
+ { meanTime: 'Produces a report summary showing the slowest running tests'},
72
+ { html: 'Generates an HTML report of the test results'}
73
+ ]
74
+
75
+
76
+ ACCEPTANCE_TEST_FILE_CONTENT = %Q(
77
+ require_relative '../test_helper.rb'
78
+
79
+ class AcceptanceTest
80
+ def test_home
81
+ visit "/"
82
+ assert_content "Hello from Cuba Genie"
83
+ end
84
+ end
85
+ )
86
+
87
+
88
+ FUNCTIONAL_TEST_FILE_CONTENT = %Q(
89
+ require_relative '../test_helper.rb'
90
+
91
+ class RackTest
92
+
93
+ def test_hello_world
94
+ get '/'
95
+ assert last_response.ok?
96
+ assert last_response.body.match(/Hello from Cuba Genie/)
97
+ end
98
+
99
+ end
100
+ )
101
+
102
+ GEM_FILE_CONTENT = %Q(
103
+ source "https://rubygems.org"
104
+ gem 'cuba'
105
+ gem "mote"
106
+ gem "mote-render"
107
+
108
+ group :development, :test do
109
+ gem 'pry-byebug'
110
+ gem 'minitest-reporters'
111
+ gem 'shotgun'
112
+ end
113
+ )
114
+
115
+
116
+ RAKE_FILE_CONTENT = %q(
117
+ require 'rake/testtask'
118
+
119
+ namespace :test do
120
+
121
+ Rake::TestTask.new(:all) do |t|
122
+ t.libs = %w(lib test)
123
+ t.pattern = "test/**/*_test.rb"
124
+ end
125
+
126
+
127
+ %w(functional acceptance).each do |name|
128
+ Rake::TestTask.new(name) do |t|
129
+ t.libs = %W(lib/#{ name } test test/#{ name })
130
+ t.pattern = "test/#{ name }/**/*_test.rb"
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ task test: ["test:all"]
137
+ task default: "test"
138
+
139
+ )
140
+
141
+
142
+ BOOTSTRAP_CSS = %Q(
143
+ <!-- Bootstrap core CSS -->
144
+ <link href="css/bootstrap.min.css" rel="stylesheet">
145
+ <!-- Custom styles for this template -->
146
+ <link href="css/jumbotron.css" rel="stylesheet">
147
+ )
148
+
149
+ BOOTSTRAP_JS = %Q(
150
+ <!-- Bootstrap core JavaScript
151
+ ================================================== -->
152
+ <!-- Placed at the end of the document so the pages load faster -->
153
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
154
+ <script src="js/bootstrap.min.js"></script>
155
+ )
156
+
157
+
158
+ end #module
@@ -0,0 +1,10 @@
1
+ module ContentHelpers
2
+
3
+ def titlecase
4
+ self.slice(0,1).capitalize + self.slice(1..-1)
5
+ end
6
+
7
+ end #module
8
+
9
+
10
+
@@ -0,0 +1,91 @@
1
+ require 'fileutils'
2
+ require_relative 'content'
3
+
4
+ module CubaGenie
5
+ require 'pry'
6
+
7
+ class CubaSetup
8
+ include Content
9
+ attr_reader :description, :error, :project_name
10
+
11
+ def initialize(project_name, minitest, capybara)
12
+ @description = "Creating Cuba setup"
13
+ @project_name = project_name
14
+ @minitest = minitest
15
+ @capybara = capybara
16
+ @files_created = []
17
+ @dirs_created = []
18
+ end
19
+
20
+ def execute
21
+
22
+ FileUtils.mkdir @project_name
23
+ @dirs_created << @project_name
24
+ FileUtils.chdir @project_name
25
+ create_app_file
26
+ create_rack_file
27
+ create_gem_file
28
+ create_ruby_version_file
29
+ create_ruby_gemset_file
30
+ true
31
+ rescue Exception => e
32
+ @error = e.message and false
33
+ end
34
+
35
+ def unexecute
36
+ puts "rolling back Cuba basic setup" unless ENV['RACK_ENV'] == 'test'
37
+ @files_created.each do |file_path|
38
+ File.delete file_path if File.exist? file_path
39
+ end
40
+ @dirs_created.each do |dir_name|
41
+ FileUtils.rm_rf(dir_name) if Dir.exist? dir_name
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def create_app_file
48
+ file_name = "#{@project_name}.rb"
49
+ File.open(file_name, 'w') {|f| f.write(APP_FILE_CONTENT) }
50
+ @files_created << "#{Dir.pwd}/#{file_name}"
51
+ end
52
+
53
+ def create_rack_file
54
+ File.open('config.ru', 'w') {|f| f.write(RACK_FILE_CONTENT % @project_name) }
55
+
56
+ @files_created << "#{Dir.pwd}/config.ru"
57
+ end
58
+
59
+ def create_gem_file
60
+ File.open('Gemfile', 'w') do |f|
61
+ if @minitest
62
+ gems_to_add = "\s\sgem 'rack-test'"
63
+ if @capybara
64
+ gems_to_add = "\s\sgem 'rack-test'" \
65
+ "\n\s\sgem 'minitest-capybara'" \
66
+ "\n\s\sgem 'selenium-webdriver'"
67
+ end
68
+ f.write GEM_FILE_CONTENT.split("\n").insert(8, gems_to_add).join("\n")
69
+ else
70
+ f.write GEM_FILE_CONTENT
71
+ end
72
+ end
73
+ @files_created << "#{Dir.pwd}/Gemfile"
74
+ end
75
+
76
+ def create_ruby_version_file
77
+ File.open('.ruby-version', 'w') {|f| f.write(get_ruby_version) }
78
+ @files_created << "#{Dir.pwd}/.ruby-version"
79
+ end
80
+
81
+ def create_ruby_gemset_file
82
+ File.open('.ruby-gemset', 'w') {|f| f.write(project_name) }
83
+ @files_created << "#{Dir.pwd}/.ruby-gemset"
84
+ end
85
+
86
+ def get_ruby_version
87
+ %x(ruby -v).slice(/(\d\.){2}\d/)
88
+ end
89
+
90
+ end #class
91
+ end #module
@@ -0,0 +1,38 @@
1
+ HOME_VIEW_CONTENT = %Q(
2
+ <div class="jumbotron">
3
+ <div class="container">
4
+ <h1>Hello from Cuba Genie!</h1>
5
+ <p> This is a <a href="http://cuba.is">Cuba</a> skeleton app,
6
+ generated by <a href="https://gitlab.com/RedFred7/cuba-genie">Cuba Genie</a>. What you see is styled by <a href="http://getbootstrap.com">Bootstrap</a> and rendered using the <a href="http://github.com/soveran/mote">Mote</a> templating engine..</p>
7
+ <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more &raquo;</a></p>
8
+ </div>
9
+ </div>
10
+
11
+ <div class="container">
12
+ <!-- Example row of columns -->
13
+ <div class="row">
14
+ <div class="col-md-4">
15
+ <h2>Views</h2>
16
+ <p>The page you are looking at was generated by <code>%s.rb</code>, and the content is located at <code>views/home.mote</code>. Add your own templates under the <code>views</code> directory to customize your site's look. </p>
17
+ <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
18
+ </div>
19
+ <div class="col-md-4">
20
+
21
+ <h2>Testing</h2>
22
+ <p>There are some ready-made test file templates under the <code>test</code> direcory. Add your own tests, then run <code>rake</code> on the command line</p>
23
+ <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
24
+ </div>
25
+ <div class="col-md-4">
26
+ <h2>Running the app</h2>
27
+ <p>You can start your app server by running <code>rackup</code> in your app directory. However, if you're developing your app and you want to use an auto-reloading server, run <code>shotgun</code>. <em>N.B</em>: if you use shotgun, make sure to change your Capybara app_host setting in <code>test_helper.rb</code> to <code>http://localhost:9292</code>. </p>
28
+ <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
29
+ </div>
30
+ </div>
31
+
32
+ <hr>
33
+
34
+ <footer>
35
+ <p>&copy; your company name here </p>
36
+ </footer>
37
+ </div> <!-- /container -->
38
+ )
@@ -0,0 +1,54 @@
1
+ LAYOUT_VIEW_CONTENT = %Q(
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
9
+ <meta name="description" content="">
10
+ <meta name="author" content="">
11
+ <link rel="icon" href="favicon.ico">
12
+
13
+ <title>{{title}}</title>
14
+
15
+ %s
16
+
17
+ </head>
18
+
19
+ <body>
20
+
21
+ <nav class="navbar navbar-inverse navbar-fixed-top">
22
+ <div class="container">
23
+ <div class="navbar-header">
24
+ <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
25
+ <span class="sr-only">Toggle navigation</span>
26
+ <span class="icon-bar"></span>
27
+ <span class="icon-bar"></span>
28
+ <span class="icon-bar"></span>
29
+ </button>
30
+ <a class="navbar-brand" href="#">%s</a>
31
+ </div>
32
+ <div id="navbar" class="navbar-collapse collapse">
33
+ <form class="navbar-form navbar-right">
34
+ <div class="form-group">
35
+ <input type="text" placeholder="Email" class="form-control">
36
+ </div>
37
+ <div class="form-group">
38
+ <input type="password" placeholder="Password" class="form-control">
39
+ </div>
40
+ <button type="submit" class="btn btn-success">Sign in</button>
41
+ </form>
42
+ </div><!--/.navbar-collapse -->
43
+ </div>
44
+ </nav>
45
+
46
+ {{ content }}
47
+
48
+ %s
49
+
50
+ </body>
51
+ </html>
52
+
53
+
54
+ )
@@ -0,0 +1,85 @@
1
+ require 'fileutils'
2
+ require_relative 'content'
3
+
4
+ module CubaGenie
5
+
6
+ class MinitestSetup
7
+ include Content
8
+
9
+ attr_reader :description, :error
10
+ attr_writer :test_helper
11
+
12
+ def initialize(project_name, reporter='Default', capybara_setup=false)
13
+ @description = (capybara_setup ?
14
+ "Setting up Minitest functional and acceptance tests" :
15
+ "Setting up Minitest functional tests")
16
+ @capybara_setup = capybara_setup
17
+ @project_name = project_name
18
+ @reporter = reporter
19
+ @files_created, @dirs_created = [], []
20
+ @test_helper = "test/test_helper.rb"
21
+ end
22
+
23
+ def execute
24
+ FileUtils.mkdir_p "test/functional"
25
+ @dirs_created << "test" << "test/functional"
26
+ if @capybara_setup
27
+ FileUtils.mkdir_p "test/acceptance"
28
+ @dirs_created << "test/acceptance"
29
+ end
30
+ create_test_helper
31
+ create_rake_file
32
+ create_functional_test
33
+ create_acceptance_test if @capybara_setup
34
+ true
35
+ rescue Exception => e
36
+ @error = e.message and false
37
+ end
38
+
39
+ def unexecute
40
+ puts "rolling back test" unless ENV['RACK_ENV'] == 'test'
41
+ # FileUtils.chdir @parent_dir
42
+ @files_created.each do |file_path|
43
+ File.delete file_path if File.exist? file_path
44
+ end
45
+ @dirs_created.each do |dir_name|
46
+ FileUtils.rm_rf(dir_name) if Dir.exist? dir_name
47
+ end
48
+ end
49
+
50
+
51
+ private
52
+ def create_test_helper
53
+
54
+ gem_line_capybara = %q(require 'minitest/capybara')
55
+ require_line = (@capybara_setup ? gem_line_capybara : nil )
56
+ content = TEST_HELPER_CONTENT_CORE % [@reporter, require_line, @project_name]
57
+ content = (content + TEST_HELPER_CONTENT_CAPYBARA) if @capybara_setup
58
+ File.open(@test_helper, 'w') {|f| f.write(content) }
59
+ @files_created << @test_helper
60
+
61
+ end
62
+
63
+ def create_rake_file
64
+ File.open("Rakefile", 'w') {|f| f.write( RAKE_FILE_CONTENT) }
65
+ @files_created << "#{Dir.pwd}/Rakefile"
66
+ end
67
+
68
+ def create_functional_test
69
+ file_path = 'test/functional/main_test.rb'
70
+ File.open(file_path, 'w') {|f| f.write(FUNCTIONAL_TEST_FILE_CONTENT) }
71
+ @files_created << "#{Dir.pwd}/#{file_path}"
72
+
73
+ end
74
+
75
+ def create_acceptance_test
76
+ file_path = 'test/acceptance/browser_test.rb'
77
+ File.open(file_path, 'w') {|f| f.write(ACCEPTANCE_TEST_FILE_CONTENT) }
78
+ @files_created << "#{Dir.pwd}/#{file_path}"
79
+ end
80
+
81
+
82
+
83
+ end #class
84
+
85
+ end #module
@@ -0,0 +1,3 @@
1
+ module CubaGenie
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,104 @@
1
+ require 'fileutils'
2
+ require_relative 'content'
3
+ require_relative 'home_view_content'
4
+ require_relative 'layout_view_content'
5
+
6
+ module CubaGenie
7
+
8
+ ALLOWED_BOOTSTRAP_VERSIONS = %w(3.3.0 3.3.5 3.3.6 4.0.0-alpha.2)
9
+
10
+ class ViewsSetup
11
+ require 'open-uri'
12
+ require 'zip'
13
+
14
+ include Content
15
+ attr_reader :description, :error, :project_name
16
+
17
+ def initialize(project_name, bootstrap_version='n', template_engine=:mote)
18
+ @project_name = project_name
19
+ #TODO: allow for choice of different template engines
20
+ @description = 'Setting up views'
21
+ @files_created = []
22
+ @dirs_created = []
23
+ @bootstrap_version = bootstrap_version
24
+ end
25
+
26
+ def execute
27
+ layout_view_formatters = [nil, @project_name.capitalize, nil]
28
+
29
+ if ALLOWED_BOOTSTRAP_VERSIONS.include? @bootstrap_version
30
+ bootstrap_location =
31
+ "https://github.com/twbs/bootstrap/releases/download/v#{@bootstrap_version}/bootstrap-#{@bootstrap_version}-dist.zip"
32
+ download_bootstrap_from bootstrap_location
33
+ extract_bootstrap_to 'public'
34
+ layout_view_formatters = [BOOTSTRAP_CSS, @project_name.capitalize, BOOTSTRAP_JS]
35
+ end
36
+ create_view_files(layout_view_formatters)
37
+ true
38
+ rescue Exception => e
39
+ @error = e.message and false
40
+ end
41
+
42
+ def unexecute
43
+ puts "rolling back views" unless ENV['RACK_ENV'] == 'test'
44
+ @files_created.each do |file_path|
45
+ File.delete file_path if File.exist? file_path
46
+ end
47
+ @dirs_created.each do |dir_name|
48
+ FileUtils.rm_rf(dir_name) if Dir.exist? dir_name
49
+ end
50
+ end
51
+
52
+ private
53
+ def create_view_files(layout_view_formatters)
54
+ FileUtils.mkdir "views"
55
+ @dirs_created << "views"
56
+ home_file, layout_file = 'views/home.mote', 'views/layout.mote'
57
+ File.open(home_file, 'w') {|f| f.write(HOME_VIEW_CONTENT % @project_name) }
58
+ File.open(layout_file, 'w') {|f| f.write(LAYOUT_VIEW_CONTENT % layout_view_formatters) }
59
+ @files_created << "#{Dir.pwd}/#{home_file}" << "#{Dir.pwd}/#{layout_file}"
60
+ end
61
+
62
+
63
+
64
+ def download_bootstrap_from(location)
65
+ FileUtils.mkdir "temp"
66
+ target = 'temp/bootstrap.zip'
67
+ open(target, 'wb') do |file|
68
+ file << open(location).read
69
+ end
70
+
71
+ # add the jumbotron css to zip file
72
+ Zip::File.open(target, Zip::File::CREATE) do |zipfile|
73
+ zipfile.get_output_stream("css/jumbotron.css") do |f|
74
+ f.puts %Q(
75
+ body {
76
+ padding-top: 50px;
77
+ padding-bottom: 20px;
78
+ }
79
+ )
80
+ end
81
+ end
82
+
83
+ target
84
+ end
85
+
86
+
87
+ def extract_bootstrap_to(directory)
88
+ FileUtils.mkdir directory
89
+
90
+ Zip::File.open('temp/bootstrap.zip') do |zip_file|
91
+ zip_file.each do |entry|
92
+ puts "...extracting #{entry.name}"
93
+ new_name = entry.name.gsub("bootstrap-#{@bootstrap_version}-dist", "")
94
+ entry.extract("#{directory}/#{new_name}")
95
+
96
+ end
97
+ end
98
+
99
+ @dirs_created << directory
100
+ FileUtils.rm_rf('temp')
101
+ end
102
+
103
+ end #class
104
+ end #module
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuba_genie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fred Heath
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakefs
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: m
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubyzip
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: CubaGenie creates a skeleton Cuba app, configured to your preferences,
154
+ which may include view templates, test templates, CSS framework and many more.
155
+ email:
156
+ - fred_h@bootstrap.me.uk
157
+ executables:
158
+ - console
159
+ - cuba_genie
160
+ - setup
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - ".gitignore"
165
+ - ".travis.yml"
166
+ - Gemfile
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - cuba_genie.gemspec
171
+ - exe/console
172
+ - exe/cuba_genie
173
+ - exe/setup
174
+ - lib/cuba_genie.rb
175
+ - lib/cuba_genie/command_list.rb
176
+ - lib/cuba_genie/content.rb
177
+ - lib/cuba_genie/content_helpers.rb
178
+ - lib/cuba_genie/cuba_setup.rb
179
+ - lib/cuba_genie/home_view_content.rb
180
+ - lib/cuba_genie/layout_view_content.rb
181
+ - lib/cuba_genie/minitest_setup.rb
182
+ - lib/cuba_genie/version.rb
183
+ - lib/cuba_genie/views_setup.rb
184
+ homepage: https://gitlab.com/RedFred7/cuba-genie
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 2.4.8
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: CubaGenie is a generator gem that sets up all the infrastructure you need
208
+ in order to be immediately productive with the Cuba web development DSL
209
+ test_files: []