buildybuild 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +9 -0
- data/buildybuild.gemspec +26 -0
- data/lib/buildybuild.rb +7 -0
- data/lib/buildybuild/version.rb +3 -0
- data/lib/generators/buildybuild/cms/cms_generator.rb +66 -0
- data/lib/generators/buildybuild/cms/templates/cms_controller.rb +41 -0
- data/lib/generators/buildybuild/cms/templates/cms_edit_view.html.haml +2 -0
- data/lib/generators/buildybuild/cms/templates/cms_form_partial.html.haml +8 -0
- data/lib/generators/buildybuild/cms/templates/cms_migration.rb +11 -0
- data/lib/generators/buildybuild/cms/templates/cms_model.rb +15 -0
- data/lib/generators/buildybuild/cms/templates/cms_new_view.html.haml +2 -0
- data/lib/generators/buildybuild/cms/templates/cms_show_view.html.haml +10 -0
- data/test/generators/buildybuild/cms/cms_generator_test.rb +39 -0
- data/test/test_helper.rb +8 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Hashrocket Workstation
|
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,85 @@
|
|
1
|
+
# Buildybuild
|
2
|
+
|
3
|
+
Buildybuild is a rails generator that gives you everything you need to create a cms.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
$ gem 'buildybuild'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install buildybuild
|
23
|
+
```
|
24
|
+
|
25
|
+
**Note:** There are runtime dependencies in Buildybuild so you'll have to add the following if buildybuild is not in your Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'decent_exposure', '2.0.0.rc1'
|
29
|
+
gem 'haml-rails'
|
30
|
+
gem 'formal'
|
31
|
+
gem 'rdiscount'
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
This is a rails generator so run the following command:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
$ rails generate buildybuild:cms
|
40
|
+
|
41
|
+
# you can pass a name for the generated resource. Default is "page" i.e.:
|
42
|
+
|
43
|
+
$ rails generate buildybuild:cms static_page
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
This will create the following files:
|
48
|
+
|
49
|
+
- app/models/page.rb
|
50
|
+
- db/migrate/[timestamp]\_create\_pages.rb
|
51
|
+
- app/controllers/pages\_controller.rb
|
52
|
+
- app/views/pages/new.html.haml
|
53
|
+
- app/views/pages/edit.html.haml
|
54
|
+
- app/views/pages/show.html.haml
|
55
|
+
- app/views/pages/\_form.html.haml
|
56
|
+
|
57
|
+
and appends the following to the bottom of your routes file:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
resources :pages, only: [:new, :create]
|
61
|
+
|
62
|
+
#keep these at the bottom of your file. They should be the last routes.
|
63
|
+
get "/:slug", to: "pages#show", as: :slug
|
64
|
+
get "/:slug/edit", to: "pages#edit", as: :edit_slug
|
65
|
+
put "/:slug", to: "pages#update", as: :slug
|
66
|
+
post "/:slug", to: "pages#destroy", as: :slug
|
67
|
+
```
|
68
|
+
|
69
|
+
### Next
|
70
|
+
|
71
|
+
run the migration
|
72
|
+
|
73
|
+
```bash
|
74
|
+
rake db:migrate
|
75
|
+
```
|
76
|
+
|
77
|
+
And you're set. Now you can go to "http://localhost:3000/pages/new" and see your new Content Management System in action!
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. Fork it
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/buildybuild.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'buildybuild/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "buildybuild"
|
8
|
+
gem.version = Buildybuild::VERSION
|
9
|
+
gem.authors = ["Hashrocket Workstation"]
|
10
|
+
gem.email = ["dev@hashrocket.com"]
|
11
|
+
gem.description = %q{Generators for adding a CMS your site}
|
12
|
+
gem.summary = %q{Create a cms that is not behind the scenes}
|
13
|
+
gem.homepage = "https://github.com/mrmicachooper/buildybuild"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "formal"
|
21
|
+
gem.add_runtime_dependency "decent_exposure", "2.0.0.rc1"
|
22
|
+
gem.add_runtime_dependency "haml-rails"
|
23
|
+
gem.add_runtime_dependency "rdiscount"
|
24
|
+
|
25
|
+
gem.add_development_dependency "railties"
|
26
|
+
end
|
data/lib/buildybuild.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module Buildybuild
|
2
|
+
class CmsGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :model_name, type: :string, default: "page"
|
7
|
+
|
8
|
+
def generate_model
|
9
|
+
template("cms_model.rb", "app/models/#{file_name}.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_migration
|
13
|
+
time_stamp = Time.now.strftime('%Y%m%d%I%M%S')
|
14
|
+
template("cms_migration.rb", "db/migrate/#{time_stamp}_create_#{file_names}.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_controller
|
18
|
+
template("cms_controller.rb", "app/controllers/#{file_names}_controller.rb")
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_views
|
22
|
+
template("cms_new_view.html.haml", "app/views/#{file_names}/new.html.haml")
|
23
|
+
template("cms_edit_view.html.haml", "app/views/#{file_names}/edit.html.haml")
|
24
|
+
template("cms_show_view.html.haml", "app/views/#{file_names}/show.html.haml")
|
25
|
+
template("cms_form_partial.html.haml", "app/views/#{file_names}/_form.html.haml")
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_routes
|
29
|
+
insert_into_file "config/routes.rb", generated_routes, before: /^end\s*$/
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def generated_routes
|
35
|
+
%Q(
|
36
|
+
resources :pages, only: [:new, :create]
|
37
|
+
|
38
|
+
#keep these at the bottom of your file. They should be the last routes.
|
39
|
+
get "/:slug", to: "pages#show", as: :slug
|
40
|
+
get "/:slug/edit", to: "pages#edit", as: :edit_slug
|
41
|
+
put "/:slug", to: "pages#update", as: :slug
|
42
|
+
post "/:slug", to: "pages#destroy", as: :slug\n\n)
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_name
|
46
|
+
model_name.underscore
|
47
|
+
end
|
48
|
+
|
49
|
+
def file_names
|
50
|
+
model_name.pluralize.underscore
|
51
|
+
end
|
52
|
+
|
53
|
+
def klass
|
54
|
+
file_name.camelize
|
55
|
+
end
|
56
|
+
|
57
|
+
def klasses
|
58
|
+
file_name.pluralize.camelize
|
59
|
+
end
|
60
|
+
|
61
|
+
def controller_name
|
62
|
+
"#{file_name.pluralize}Controller".camelize
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class <%= controller_name %> < ApplicationController
|
2
|
+
|
3
|
+
expose(:<%= file_name.pluralize %>)
|
4
|
+
expose(:<%= file_name %>, finder: :find_by_slug, finder_parameter: :slug)
|
5
|
+
expose(:new_<%= file_name %>, model: <%= klass %>)
|
6
|
+
expose(:slug) { params[:slug] }
|
7
|
+
|
8
|
+
# Move this to the ApplicationController if you want to have
|
9
|
+
# the navigation in your Application Layout
|
10
|
+
expose(:<%= file_name%>_slugs ) { <%= klass %>.select(:slug).map(&:slug) }
|
11
|
+
|
12
|
+
def show
|
13
|
+
if template_exists? "<%= file_names %>/#{slug.underscore}"
|
14
|
+
render slug.underscore
|
15
|
+
else
|
16
|
+
render "show"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
if new_<%= file_name %>.save
|
22
|
+
redirect_to slug_path(new_<%= file_name %>.slug)
|
23
|
+
else
|
24
|
+
render 'new'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
if <%= file_name %>.save
|
30
|
+
redirect_to slug_path(<%= file_name %>.slug)
|
31
|
+
else
|
32
|
+
render 'edit'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy
|
37
|
+
<%= file_name %>.destroy
|
38
|
+
redirect_to :root, message: "#{<%= file_name %>.name} was deleted."
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= klass %> < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessible :body, :name, :slug
|
4
|
+
|
5
|
+
default_scope order('created_at DESC, updated_at DESC')
|
6
|
+
|
7
|
+
validates_uniqueness_of :name
|
8
|
+
|
9
|
+
before_save :update_slug
|
10
|
+
|
11
|
+
def update_slug
|
12
|
+
self.slug = name.parameterize
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BuildybuildCmsGeneratorTest < Rails::Generators::TestCase
|
4
|
+
tests Buildybuild::CmsGenerator
|
5
|
+
destination File.expand_path("../../../../tmp", File.dirname(__FILE__))
|
6
|
+
setup :prepare_destination
|
7
|
+
|
8
|
+
test "model is generated" do
|
9
|
+
generator.generate_model
|
10
|
+
assert_file "app/models/page.rb", /class Page/
|
11
|
+
end
|
12
|
+
|
13
|
+
test "migration is generated" do
|
14
|
+
generator.generate_migration
|
15
|
+
assert_migration "db/migrate/create_pages.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
test "controller is generated" do
|
19
|
+
generator.generate_controller
|
20
|
+
assert_file "app/controllers/pages_controller.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
test "views are generated" do
|
24
|
+
generator.generate_views
|
25
|
+
assert_file "app/views/pages/show.html.haml", /:markdown/
|
26
|
+
assert_file "app/views/pages/edit.html.haml", / render partial: "form", locals: { f:f }/
|
27
|
+
assert_file "app/views/pages/new.html.haml", / render partial: "form", locals: { f:f }/
|
28
|
+
assert_file "app/views/pages/_form.html.haml", /f\.label :name/
|
29
|
+
end
|
30
|
+
|
31
|
+
test "routes are updated" do
|
32
|
+
#create the file in the test so we can insert into it.
|
33
|
+
generator.create_file("config/routes.rb", "class Routes \n\nend")
|
34
|
+
generator.add_routes
|
35
|
+
assert_file "config/routes.rb", /get "\/:slug", to: "pages#show", as: :slug/
|
36
|
+
assert_file "config/routes.rb", /:slug\n\nend$/
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buildybuild
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hashrocket Workstation
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: formal
|
16
|
+
requirement: &70169109374020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70169109374020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: decent_exposure
|
27
|
+
requirement: &70169109373300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0.rc1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70169109373300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: haml-rails
|
38
|
+
requirement: &70169109372580 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70169109372580
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rdiscount
|
49
|
+
requirement: &70169109371900 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70169109371900
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: railties
|
60
|
+
requirement: &70169109371260 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70169109371260
|
69
|
+
description: Generators for adding a CMS your site
|
70
|
+
email:
|
71
|
+
- dev@hashrocket.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- buildybuild.gemspec
|
82
|
+
- lib/buildybuild.rb
|
83
|
+
- lib/buildybuild/version.rb
|
84
|
+
- lib/generators/buildybuild/cms/cms_generator.rb
|
85
|
+
- lib/generators/buildybuild/cms/templates/cms_controller.rb
|
86
|
+
- lib/generators/buildybuild/cms/templates/cms_edit_view.html.haml
|
87
|
+
- lib/generators/buildybuild/cms/templates/cms_form_partial.html.haml
|
88
|
+
- lib/generators/buildybuild/cms/templates/cms_migration.rb
|
89
|
+
- lib/generators/buildybuild/cms/templates/cms_model.rb
|
90
|
+
- lib/generators/buildybuild/cms/templates/cms_new_view.html.haml
|
91
|
+
- lib/generators/buildybuild/cms/templates/cms_show_view.html.haml
|
92
|
+
- test/generators/buildybuild/cms/cms_generator_test.rb
|
93
|
+
- test/test_helper.rb
|
94
|
+
homepage: https://github.com/mrmicachooper/buildybuild
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.10
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Create a cms that is not behind the scenes
|
118
|
+
test_files:
|
119
|
+
- test/generators/buildybuild/cms/cms_generator_test.rb
|
120
|
+
- test/test_helper.rb
|