corneal 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c72255b709457456984468ae88732cf41560024
4
- data.tar.gz: 35dc9fb6162d07a9613bf4cf5e22a2bac58dd3bf
3
+ metadata.gz: b04ca4b0bfe84f93a60c4269a6834d11db6ba59e
4
+ data.tar.gz: fe39aff8397ed7bf2b702027ba23fd977986551a
5
5
  SHA512:
6
- metadata.gz: b68e2d04e08205ae6de10c4ca8db909ec6045a6faa3388ddd10aa38a88627594cd7a55b4c529852f558d5371589c3b468191ad3499ef5797881be2b654fff5fc
7
- data.tar.gz: b6c5dcc630915ec6a2a5a5bd1d18038ba5bc4c491828399b6767dfdd11b1d9c9a04c1f641c1d8a5255329aebc95cc7e542a46c006dc6ba4aab1511b17c4ace28
6
+ metadata.gz: dc82867fab95ca36c7eb4dbfc30e06f09fb07dfa4602d4b6c854a537f82ca8724cf805d13f9a4f02f6502ccac52d3461f0f745f457a0fa9b713c4e6ef6e5edba
7
+ data.tar.gz: 4a542289889739a72a008dbee98192b3f356558ea86b35895370bc21f3f4eadfec7d42492195b1a5be0845fd27ef66ed2da82e563aa5bdaeb368d281d0560f76
data/Gemfile CHANGED
@@ -2,7 +2,10 @@ source 'https://rubygems.org/'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'active_model_serializers', '~> 0.10.0.rc1'
6
+
5
7
  group :development do
6
8
  gem "rake", "~> 10.0"
7
9
  gem "fakefs", "~> 0.4"
10
+ gem "pry"
8
11
  end
@@ -1,23 +1,92 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hazel (0.0.8)
4
+ corneal (1.0.0)
5
+ activesupport (~> 5.0)
5
6
  thor (~> 0.18)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ actionpack (5.0.0.1)
12
+ actionview (= 5.0.0.1)
13
+ activesupport (= 5.0.0.1)
14
+ rack (~> 2.0)
15
+ rack-test (~> 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (5.0.0.1)
19
+ activesupport (= 5.0.0.1)
20
+ builder (~> 3.1)
21
+ erubis (~> 2.7.0)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ active_model_serializers (0.10.2)
25
+ actionpack (>= 4.1, < 6)
26
+ activemodel (>= 4.1, < 6)
27
+ jsonapi (~> 0.1.1.beta2)
28
+ railties (>= 4.1, < 6)
29
+ activemodel (5.0.0.1)
30
+ activesupport (= 5.0.0.1)
31
+ activesupport (5.0.0.1)
32
+ concurrent-ruby (~> 1.0, >= 1.0.2)
33
+ i18n (~> 0.7)
34
+ minitest (~> 5.1)
35
+ tzinfo (~> 1.1)
36
+ builder (3.2.2)
37
+ coderay (1.1.1)
38
+ concurrent-ruby (1.0.2)
39
+ erubis (2.7.0)
10
40
  fakefs (0.4.3)
41
+ i18n (0.7.0)
42
+ json (1.8.3)
43
+ jsonapi (0.1.1.beta2)
44
+ json (~> 1.8)
45
+ loofah (2.0.3)
46
+ nokogiri (>= 1.5.9)
47
+ method_source (0.8.2)
48
+ mini_portile2 (2.1.0)
11
49
  minitest (5.2.0)
50
+ nokogiri (1.6.8)
51
+ mini_portile2 (~> 2.1.0)
52
+ pkg-config (~> 1.1.7)
53
+ pkg-config (1.1.7)
54
+ pry (0.10.4)
55
+ coderay (~> 1.1.0)
56
+ method_source (~> 0.8.1)
57
+ slop (~> 3.4)
58
+ rack (2.0.1)
59
+ rack-test (0.6.3)
60
+ rack (>= 1.0)
61
+ rails-dom-testing (2.0.1)
62
+ activesupport (>= 4.2.0, < 6.0)
63
+ nokogiri (~> 1.6.0)
64
+ rails-html-sanitizer (1.0.3)
65
+ loofah (~> 2.0)
66
+ railties (5.0.0.1)
67
+ actionpack (= 5.0.0.1)
68
+ activesupport (= 5.0.0.1)
69
+ method_source
70
+ rake (>= 0.8.7)
71
+ thor (>= 0.18.1, < 2.0)
12
72
  rake (10.1.1)
13
- thor (0.18.1)
73
+ slop (3.6.0)
74
+ thor (0.19.1)
75
+ thread_safe (0.3.5)
76
+ tzinfo (1.2.2)
77
+ thread_safe (~> 0.1)
14
78
 
15
79
  PLATFORMS
16
80
  ruby
17
81
 
18
82
  DEPENDENCIES
19
- bundler (~> 1.5.1)
83
+ active_model_serializers (~> 0.10.0.rc1)
84
+ bundler (~> 1.5, >= 1.5.1)
85
+ corneal!
20
86
  fakefs (~> 0.4)
21
- hazel!
22
87
  minitest (~> 5.2)
88
+ pry
23
89
  rake (~> 10.0)
90
+
91
+ BUNDLED WITH
92
+ 1.12.5
data/README.md CHANGED
@@ -4,13 +4,13 @@
4
4
 
5
5
  When I was creating my first major Sinatra project, [Cook This Way](https://github.com/thebrianemory/cook-this-way), while doing [Learn Verified](https://learn.co/with/thebrianemory), I was looking for a way to build a Sinatra skeleton similar to running
6
6
 
7
- rails new app-name
7
+ rails new APP-NAME
8
8
 
9
9
  [Hazel](https://github.com/c7/hazel) was the closest thing I could find and this gem is based largely off of it. While it did provide a pretty good initial setup, I still had to tweak some things. The views were sitting in the root directory while I wanted them to reside in an app folder along with my models and controllers. There was also no environment.rb in the config folder as I had become accustom to having.
10
10
 
11
11
  I also wanted to create a gem for future Learn students so they could easily get started building their projects. Although built with them in mind, this can get you off and running with any Sinatra app.
12
12
 
13
- Install the gem, run `corneal new app-name`, run `bundle install`, and you're all set! You can start up your server with `shotgun` and verify everything is working. It is as simple as that.
13
+ Install the gem, run `corneal new APP-NAME`, run `bundle install`, and you're all set! You can start up your server with `shotgun` and verify everything is working. It is as simple as that.
14
14
 
15
15
  It uses a file structure similar to what you would see with Rails.
16
16
 
@@ -55,18 +55,19 @@ Directory structure:
55
55
  corneal -v # Show Corneal version number
56
56
  corneal help [COMMAND] # Describe available commands or one specific command
57
57
  corneal model NAME # Generate a model
58
- corneal new APP_PATH # Creates a new Sinatra application
58
+ corneal scaffold NAME # Generates your model, controller, and views
59
+ corneal new APP-NAME # Creates a new Sinatra application
59
60
  ```
60
61
 
61
62
  ## Using Corneal
62
63
 
63
64
  To generate your app:
64
65
 
65
- corneal new app-name
66
+ corneal new APP-NAME
66
67
 
67
68
  After Corneal is done generating your app, run `bundle install` from your app's directory:
68
69
 
69
- cd app-name
70
+ cd APP-NAME
70
71
  bundle install
71
72
 
72
73
  You can then start your server with `shotgun`:
@@ -77,9 +78,32 @@ You can generate a model and migration file:
77
78
 
78
79
  corneal model NAME
79
80
 
80
- You can also add your model attributes when you generate the model and have them added to your migration file:
81
+ You can also generate an entire MVC structure complete with a migration file:
81
82
 
82
- corneal model NAME name:string age:integer
83
+ corneal scaffold NAME
84
+
85
+ The resulting structure will look like this:
86
+
87
+ ```
88
+ └─app
89
+ ├── controllers
90
+ │ ├──application_controller.rb
91
+ │ └──new_model_controller.rb
92
+ ├── models
93
+ │ └──new_model.rb
94
+ └── views
95
+ ├──new_models
96
+ │ ├──index.html.rb.erb
97
+ │ ├──show.html.rb.erb
98
+ │ ├──new.html.rb.erb
99
+ │ └──edit.html.rb.erb
100
+ ├── layout.erb
101
+ └── welcome.erb
102
+ ```
103
+
104
+ You can also add your model attributes when you generate the scaffold structure and have them added to your migration file:
105
+
106
+ corneal [model/scaffold] NAME name:string age:integer
83
107
 
84
108
  ```
85
109
  class CreateUsers < ActiveRecord::Migration
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rake/testtask"
4
4
  require "bundler/gem_tasks"
5
+ require "pry"
5
6
 
6
7
  Rake::TestTask.new(:spec) do |test|
7
8
  test.libs << 'lib' << 'spec'
@@ -9,3 +10,7 @@ Rake::TestTask.new(:spec) do |test|
9
10
  end
10
11
 
11
12
  task :default => :spec
13
+
14
+ task :console do
15
+ Pry.start
16
+ end
@@ -1,6 +1,7 @@
1
1
  require "extensions/string"
2
2
  require "corneal/generators/app/app_generator"
3
3
  require "corneal/generators/model/model_generator"
4
+ require "corneal/generators/scaffold/scaffold_generator"
4
5
  require "corneal/version"
5
6
  require "corneal/cli"
6
7
 
@@ -14,6 +14,7 @@ module Corneal
14
14
  # register(class_name, subcommand_alias, usage_list_string, description_string)
15
15
  register Corneal::Generators::AppGenerator, "new", "new APP_PATH", "Creates a new Sinatra application"
16
16
  register Corneal::Generators::ModelGenerator, "model", "model NAME", "Generate a model"
17
+ register Corneal::Generators::ScaffoldGenerator, "scaffold", "scaffold NAME", "Generate a model with its associated views and controllers"
17
18
 
18
19
  def self.exit_on_failure
19
20
  true
File without changes
@@ -41,7 +41,7 @@ module Corneal
41
41
 
42
42
  def create_migration
43
43
  return unless options[:migration]
44
-
44
+
45
45
  migration_files = Dir.entries("db/migrate").select { |path| !File.directory? path }
46
46
 
47
47
  if duplicate = migration_files.find { |file| file.include?(migration_name) }
@@ -0,0 +1,68 @@
1
+ require "thor/group"
2
+ require 'active_support/inflector'
3
+
4
+ module Corneal
5
+ module Generators
6
+ class ScaffoldGenerator < Thor::Group
7
+ include Thor::Actions
8
+ attr_reader :file_name, :class_name, :controller_class_name, :model_name, :migration_name, :migration_class_name, :table_name
9
+
10
+ desc "Generate an ActiveRecord model with it's associated views and controllers"
11
+ argument :name, :type => :string, :desc => "Name of the model"
12
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
13
+
14
+ class_option :migration, type: :boolean, default: true, desc: "Generate migration for model"
15
+
16
+ def self.source_root
17
+ File.dirname(__FILE__)
18
+ end
19
+
20
+ def setup
21
+ @model_name = name.singularize
22
+ @class_name = model_name.camel_case
23
+ @controller_class_name = "#{@class_name.pluralize}Controller"
24
+ @file_name = model_name.file_name
25
+ @table_name = @file_name.pluralize
26
+ @migration_name = "create_#{@table_name}"
27
+ @migration_class_name = @migration_name.camel_case
28
+
29
+ attributes.map! do |attribute|
30
+ field = attribute.split(":")
31
+ { name: field[0], type: (field[1] || "string") }
32
+ end
33
+ end
34
+
35
+ def create_model
36
+ unless model_name == name
37
+ say "[WARNING] The model name '#{name}' was recognized as a plural, using the singular '#{model_name}' instead."
38
+ end
39
+
40
+ template "templates/model.rb.erb", File.join("app/models", "#{file_name}.rb")
41
+ end
42
+
43
+ def create_views
44
+ directory "templates/views", File.join("app/views", "#{table_name}")
45
+ end
46
+
47
+ def create_controller
48
+ template "templates/controller.rb.erb", File.join("app/controllers", "#{file_name}_controller.rb")
49
+ insert_into_file "config.ru", "use #{controller_class_name}\n", :after => "run ApplicationController\n"
50
+ end
51
+
52
+ def create_migration
53
+ return unless options[:migration]
54
+
55
+ migration_files = Dir.entries("db/migrate").select { |path| !File.directory? path }
56
+
57
+ if duplicate = migration_files.find { |file| file.include?(migration_name) }
58
+ say_status :identical, "db/migrate/#{duplicate}", :blue
59
+ else
60
+ version = Time.now.utc.strftime("%Y%m%d%H%M%S")
61
+ migration_file_name = "#{version}_#{migration_name}.rb"
62
+
63
+ template "templates/migration.rb.erb", File.join("db/migrate", migration_file_name)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,35 @@
1
+ class <%= @controller_class_name %> < ApplicationController
2
+
3
+ #Index Controller
4
+ get "/<%=@table_name%>" do
5
+ erb :"/<%=@table_name%>/index.html"
6
+ end
7
+
8
+ # New Item Controllers
9
+ get "/<%=@table_name%>/new" do
10
+ erb :"/<%=@table_name%>/new.html"
11
+ end
12
+
13
+ post "/<%=@table_name%>" do
14
+ redirect "/<%=@table_name%>"
15
+ end
16
+
17
+ # Show Item Controller
18
+ get "/<%=@table_name%>/:id" do
19
+ erb :"/<%=@table_name%>/show.html"
20
+ end
21
+
22
+ # Edit Item Controller
23
+ get "/<%=@table_name%>/:id/edit" do
24
+ erb :"/<%=@table_name%>/edit.html"
25
+ end
26
+
27
+ patch "/<%=@table_name%>" do
28
+ redirect "/<%=@table_name%>/:id"
29
+ end
30
+
31
+ # Delete Item Controller
32
+ delete "/<%=@table_name%>/:id/delete" do
33
+ redirect "/<%=@table_name%>"
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute[:type] %> :<%= attribute[:name] %>
6
+ <% end %>
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1 @@
1
+ <h1>Insert the form to edit an instance of your model here.</h1>
@@ -0,0 +1 @@
1
+ <h1>This is the Model's index page.</h1>
@@ -0,0 +1 @@
1
+ <h1>Insert the form to create a new instance of your model.</h1>
@@ -0,0 +1 @@
1
+ <h1>This is the show page for an individual instance of your model.</h1>
@@ -1,7 +1,7 @@
1
1
  module Corneal
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corneal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Emory
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -111,6 +111,14 @@ files:
111
111
  - lib/corneal/generators/model/migration.rb.erb
112
112
  - lib/corneal/generators/model/model.rb.erb
113
113
  - lib/corneal/generators/model/model_generator.rb
114
+ - lib/corneal/generators/scaffold/scaffold_generator.rb
115
+ - lib/corneal/generators/scaffold/templates/controller.rb.erb
116
+ - lib/corneal/generators/scaffold/templates/migration.rb.erb
117
+ - lib/corneal/generators/scaffold/templates/model.rb.erb
118
+ - lib/corneal/generators/scaffold/templates/views/edit.html.erb
119
+ - lib/corneal/generators/scaffold/templates/views/index.html.erb
120
+ - lib/corneal/generators/scaffold/templates/views/new.html.erb
121
+ - lib/corneal/generators/scaffold/templates/views/show.html.erb
114
122
  - lib/corneal/version.rb
115
123
  - lib/extensions/string.rb
116
124
  - spec/corneal/cli_spec.rb