firstdraft_generators 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +637 -0
  5. data/Gemfile +14 -0
  6. data/Gemfile.lock +83 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.markdown +24 -0
  9. data/Rakefile +51 -0
  10. data/VERSION +1 -0
  11. data/firstdraft_generators.gemspec +85 -0
  12. data/lib/firstdraft_generators.rb +2 -0
  13. data/lib/generators/draft/layout/USAGE +49 -0
  14. data/lib/generators/draft/layout/layout_generator.rb +70 -0
  15. data/lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb +9 -0
  16. data/lib/generators/draft/layout/templates/_flashes.html.erb +17 -0
  17. data/lib/generators/draft/layout/templates/_footer.html.erb +33 -0
  18. data/lib/generators/draft/layout/templates/_navbar.html.erb +61 -0
  19. data/lib/generators/draft/layout/templates/layout.html.erb +31 -0
  20. data/lib/generators/draft/model/USAGE +14 -0
  21. data/lib/generators/draft/model/model_generator.rb +33 -0
  22. data/lib/generators/draft/resource/USAGE +11 -0
  23. data/lib/generators/draft/resource/resource_generator.rb +162 -0
  24. data/lib/generators/draft/resource/templates/controllers/controller.rb +98 -0
  25. data/lib/generators/draft/resource/templates/controllers/read_only_controller.rb +9 -0
  26. data/lib/generators/draft/resource/templates/specs/crud_spec.rb +300 -0
  27. data/lib/generators/draft/resource/templates/specs/factories.rb +34 -0
  28. data/lib/generators/draft/resource/templates/views/create_row.html.erb +13 -0
  29. data/lib/generators/draft/resource/templates/views/destroy_row.html.erb +13 -0
  30. data/lib/generators/draft/resource/templates/views/edit_form.html.erb +54 -0
  31. data/lib/generators/draft/resource/templates/views/index.html.erb +62 -0
  32. data/lib/generators/draft/resource/templates/views/new_form.html.erb +54 -0
  33. data/lib/generators/draft/resource/templates/views/show.html.erb +46 -0
  34. data/lib/generators/draft/resource/templates/views/update_row.html.erb +9 -0
  35. metadata +151 -0
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 3.5.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "juwelier", "~> 2.1.0"
13
+ gem "simplecov", ">= 0"
14
+ end
@@ -0,0 +1,83 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.4.0)
5
+ builder (3.2.3)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.3)
9
+ docile (1.1.5)
10
+ faraday (0.9.2)
11
+ multipart-post (>= 1.2, < 3)
12
+ git (1.3.0)
13
+ github_api (0.17.0)
14
+ addressable (~> 2.4.0)
15
+ descendants_tracker (~> 0.0.4)
16
+ faraday (~> 0.8, < 0.10)
17
+ hashie (>= 3.4)
18
+ mime-types (>= 1.16, < 3.0)
19
+ oauth2 (~> 1.0)
20
+ hashie (3.5.5)
21
+ highline (1.7.8)
22
+ json (1.8.6)
23
+ juwelier (2.1.3)
24
+ builder
25
+ bundler (>= 1.13)
26
+ git (>= 1.2.5)
27
+ github_api
28
+ highline (>= 1.6.15)
29
+ nokogiri (>= 1.5.10)
30
+ rake
31
+ rdoc
32
+ semver
33
+ jwt (1.5.6)
34
+ mime-types (2.99.3)
35
+ mini_portile2 (2.1.0)
36
+ multi_json (1.12.1)
37
+ multi_xml (0.6.0)
38
+ multipart-post (2.0.0)
39
+ nokogiri (1.7.1)
40
+ mini_portile2 (~> 2.1.0)
41
+ oauth2 (1.3.1)
42
+ faraday (>= 0.8, < 0.12)
43
+ jwt (~> 1.0)
44
+ multi_json (~> 1.3)
45
+ multi_xml (~> 0.5)
46
+ rack (>= 1.2, < 3)
47
+ rack (2.0.1)
48
+ rake (12.0.0)
49
+ rdoc (3.12.2)
50
+ json (~> 1.4)
51
+ rspec (3.5.0)
52
+ rspec-core (~> 3.5.0)
53
+ rspec-expectations (~> 3.5.0)
54
+ rspec-mocks (~> 3.5.0)
55
+ rspec-core (3.5.4)
56
+ rspec-support (~> 3.5.0)
57
+ rspec-expectations (3.5.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.5.0)
60
+ rspec-mocks (3.5.0)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.5.0)
63
+ rspec-support (3.5.0)
64
+ semver (1.0.1)
65
+ simplecov (0.14.1)
66
+ docile (~> 1.1.0)
67
+ json (>= 1.8, < 3)
68
+ simplecov-html (~> 0.10.0)
69
+ simplecov-html (0.10.0)
70
+ thread_safe (0.3.6)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (~> 1.0)
77
+ juwelier (~> 2.1.0)
78
+ rdoc (~> 3.12)
79
+ rspec (~> 3.5.0)
80
+ simplecov
81
+
82
+ BUNDLED WITH
83
+ 1.14.6
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 Raghu Betina
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # firstdraft_generators
2
+
3
+ This is a set of generators that help beginners learn to program. Primarily, they generate code that is more explicit and verbose and less idiomatic and “magical” than the built-in scaffold generator. It is meant to be helpful for beginners while they are still learning how things are wired together.
4
+
5
+ ## Contributing to firstdraft_generators
6
+
7
+ - Check out the latest master to make sure the feature hasn't been
8
+ implemented or the bug hasn't been fixed yet.
9
+ - Check out the issue tracker to make sure someone already hasn't
10
+ requested it and/or contributed it.
11
+ - Fork the project.
12
+ Start a feature/bugfix branch.
13
+ Commit and push until you are happy with your contribution.
14
+ Make sure to add tests for it. This is important so I don't break it
15
+ in a future version unintentionally.
16
+ - Please try not to mess with the Rakefile, version, or history. If
17
+ you want to have your own version, or is otherwise necessary, that
18
+ is fine, but please isolate to its own commit so I can cherry-pick
19
+ around it.
20
+
21
+ ## Copyright
22
+
23
+ Copyright (c) 2017 Raghu Betina. See
24
+ LICENSE.txt for further details.
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'juwelier'
15
+ Juwelier::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "firstdraft_generators"
18
+ gem.homepage = "http://github.com/raghubetina/firstdraft_generators"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Generators that help beginners learn to program.}
21
+ gem.description = %Q{This is a set of generators that help beginners learn to program. Primarily, they generate code that is more explicit and verbose and less idiomatic and “magical” than the built-in scaffold generator, which is helpful for beginners while they are learning how exactly things are wired together.}
22
+ gem.email = "raghu@firstdraft.com"
23
+ gem.authors = ["Raghu Betina"]
24
+
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Juwelier::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['spec'].execute
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "firstdraft_generators #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,85 @@
1
+ # Generated by juwelier
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: firstdraft_generators 0.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "firstdraft_generators".freeze
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Raghu Betina".freeze]
14
+ s.date = "2017-05-08"
15
+ s.description = "This is a set of generators that help beginners learn to program. Primarily, they generate code that is more explicit and verbose and less idiomatic and \u{201c}magical\u{201d} than the built-in scaffold generator, which is helpful for beginners while they are learning how exactly things are wired together.".freeze
16
+ s.email = "raghu@firstdraft.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.markdown"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".rubocop.yml",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE.txt",
28
+ "README.markdown",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "firstdraft_generators.gemspec",
32
+ "lib/firstdraft_generators.rb",
33
+ "lib/generators/draft/layout/USAGE",
34
+ "lib/generators/draft/layout/layout_generator.rb",
35
+ "lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb",
36
+ "lib/generators/draft/layout/templates/_flashes.html.erb",
37
+ "lib/generators/draft/layout/templates/_footer.html.erb",
38
+ "lib/generators/draft/layout/templates/_navbar.html.erb",
39
+ "lib/generators/draft/layout/templates/layout.html.erb",
40
+ "lib/generators/draft/model/USAGE",
41
+ "lib/generators/draft/model/model_generator.rb",
42
+ "lib/generators/draft/resource/USAGE",
43
+ "lib/generators/draft/resource/resource_generator.rb",
44
+ "lib/generators/draft/resource/templates/controllers/controller.rb",
45
+ "lib/generators/draft/resource/templates/controllers/read_only_controller.rb",
46
+ "lib/generators/draft/resource/templates/specs/crud_spec.rb",
47
+ "lib/generators/draft/resource/templates/specs/factories.rb",
48
+ "lib/generators/draft/resource/templates/views/create_row.html.erb",
49
+ "lib/generators/draft/resource/templates/views/destroy_row.html.erb",
50
+ "lib/generators/draft/resource/templates/views/edit_form.html.erb",
51
+ "lib/generators/draft/resource/templates/views/index.html.erb",
52
+ "lib/generators/draft/resource/templates/views/new_form.html.erb",
53
+ "lib/generators/draft/resource/templates/views/show.html.erb",
54
+ "lib/generators/draft/resource/templates/views/update_row.html.erb"
55
+ ]
56
+ s.homepage = "http://github.com/raghubetina/firstdraft_generators".freeze
57
+ s.licenses = ["MIT".freeze]
58
+ s.rubygems_version = "2.6.11".freeze
59
+ s.summary = "Generators that help beginners learn to program.".freeze
60
+
61
+ if s.respond_to? :specification_version then
62
+ s.specification_version = 4
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
66
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
67
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
68
+ s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
69
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
70
+ else
71
+ s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
72
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
73
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
74
+ s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
75
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
76
+ end
77
+ else
78
+ s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
79
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
80
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
81
+ s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
82
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
83
+ end
84
+ end
85
+
@@ -0,0 +1,2 @@
1
+ module FirstdraftGenerators
2
+ end
@@ -0,0 +1,49 @@
1
+ Description:
2
+
3
+ Generates a layout file with some handy utilities:
4
+
5
+ - Bootstrap (or a Bootswatch)
6
+ - Font Awesome
7
+ - A navbar with
8
+ - links to all detected index pages
9
+ - links to all detected registration and sign in forms
10
+ - Components to display flash notices and alerts
11
+ - A sticky footer
12
+
13
+ Specify "none" as the THEME_NAME to use vanilla Bootstrap; or, choose a
14
+ Bootswatch. As of this writing, available Bootswatches are:
15
+
16
+ - cerulean
17
+ - cosmo
18
+ - cyborg
19
+ - darkly
20
+ - flatly
21
+ - journal
22
+ - lumen
23
+ - none
24
+ - paper
25
+ - readable
26
+ - sandstone
27
+ - simplex
28
+ - slate
29
+ - spacelab
30
+ - superhero
31
+ - united
32
+ - yeti
33
+
34
+ WARNING: You will lose any modifications you've made to your current layout
35
+ if you choose to overwrite it. You can also specify a different filename
36
+ other than "application" with the --layout-file option.
37
+
38
+ Examples:
39
+
40
+ rails generate draft:layout
41
+
42
+ rails generate draft:layout --theme=paper
43
+
44
+ rails generate draft:layout --layout-file=some_other_filename
45
+
46
+ rails generate draft:layout --skip-cdn
47
+
48
+ (The last one omits links to CDN-hosted Bootstrap CSS, JS, and Font Awesome,
49
+ in case you are e.g. bundling them yourself using gems.)
@@ -0,0 +1,70 @@
1
+ module Draft
2
+ class LayoutGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ class_option :theme, type: :string, default: "none", desc: "Bootstrap theme"
6
+ class_option :layout_file, type: :string, default: "application", desc: "Layout filename"
7
+ class_option :skip_cdn, type: :boolean, default: false, desc: "Skip connecting CDN assets"
8
+
9
+ def generate_layout
10
+ if bootswatch?
11
+ log :insert, "Adding #{theme_name.capitalize} Bootswatch"
12
+ else
13
+ log :insert, "Adding Bootstrap"
14
+ end
15
+
16
+ log :insert, "Adding Font Awesome"
17
+ log :insert, "Adding navbar"
18
+ log :insert, "Adding alerts"
19
+ log :insert, "Adding sticky footer; you may need to add
20
+
21
+ padding-bottom: 70px
22
+
23
+ to the body of the document."
24
+
25
+ template "layout.html.erb", "app/views/layouts/#{options["layout_file"]}.html.erb"
26
+
27
+ template "_navbar.html.erb", "app/views/shared/_navbar.html.erb"
28
+
29
+ template "_flashes.html.erb", "app/views/shared/_flashes.html.erb"
30
+
31
+ template "_footer.html.erb", "app/views/shared/_footer.html.erb"
32
+
33
+ unless skip_cdn?
34
+ template "_bootstrapcdn_assets.html.erb", "app/views/shared/_bootstrapcdn_assets.html.erb"
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def bootswatch?
41
+ if theme_name.present?
42
+ theme_name != "none"
43
+ end
44
+ end
45
+
46
+ def theme_name
47
+ options["theme"].downcase
48
+ end
49
+
50
+ def skip_cdn?
51
+ options["skip_cdn"]
52
+ end
53
+
54
+ def app_resources
55
+ route_names.reject do |name|
56
+ /^rails_info.*/.match(name) || /^rails_mailers.*/.match(name) || name.pluralize != name
57
+ end
58
+ end
59
+
60
+ def devise_routes
61
+ route_names.map do |name|
62
+ /new_(.*)_registration/.match(name)
63
+ end.compact
64
+ end
65
+
66
+ def route_names
67
+ @route_names ||= Rails.application.routes.routes.map(&:name).uniq.compact
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ <% if bootswatch? -%>
2
+ <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.7/<%= theme_name %>/bootstrap.min.css">
3
+ <% else -%>
4
+ <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
5
+ <% end -%>
6
+ <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
7
+
8
+ <script src="//code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g=" crossorigin="anonymous"></script>
9
+ <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
@@ -0,0 +1,17 @@
1
+ <div class="row">
2
+ <div class="col-lg-12">
3
+ <%% if notice.present? %>
4
+ <div class="alert alert-dismissable alert-success">
5
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
6
+ <%%= notice %>
7
+ </div>
8
+ <%% end %>
9
+
10
+ <%% if alert.present? %>
11
+ <div class="alert alert-dismissable alert-warning">
12
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
13
+ <%%= alert %>
14
+ </div>
15
+ <%% end %>
16
+ </div>
17
+ </div>
@@ -0,0 +1,33 @@
1
+ <nav class="navbar navbar-default navbar-fixed-bottom" role="navigation">
2
+ <div class="container">
3
+ <div class="collapse navbar-collapse" id="collapsible-nav-links">
4
+ <ul class="nav navbar-nav">
5
+ <li>
6
+ <a href="/about">
7
+ About
8
+ </a>
9
+ </li>
10
+
11
+ <li>
12
+ <a href="https://medium.com/">
13
+ Blog
14
+ </a>
15
+ </li>
16
+ </ul>
17
+
18
+ <ul class="nav navbar-nav navbar-right">
19
+ <li>
20
+ <a href="/contact">
21
+ Contact
22
+ </a>
23
+ </li>
24
+
25
+ <li>
26
+ <a href="/faq">
27
+ FAQ
28
+ </a>
29
+ </li>
30
+ </ul>
31
+ </div><!-- /.navbar-collapse -->
32
+ </div>
33
+ </nav>