buildybuild 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Buildybuild
2
2
 
3
- Buildybuild is generator that allows you to quickly generate static with either markup or a provided cms.
3
+ Buildybuild is generator that allows you to quickly generate things like:
4
+
5
+ - static pages with either markup or a provided cms.
6
+ - an awesome active link helper
4
7
 
5
8
  ## Installation
6
9
 
@@ -22,28 +25,28 @@ Or install it yourself as:
22
25
  $ gem install buildybuild
23
26
  ```
24
27
 
25
- **Note:** There are runtime dependencies in Buildybuild so you'll have to add the following if buildybuild is not in your Gemfile:
28
+ **Note:** There are runtime dependencies in Buildybuild so you'll have to add
29
+ the following if buildybuild is not in your Gemfile:
26
30
 
27
31
  ```ruby
28
- gem 'decent_exposure', '2.0.0.rc1'
29
- gem 'haml-rails'
30
- gem 'formal'
31
- gem 'rdiscount'
32
+ gem 'decent_exposure'
33
+ gem 'haml-rails'
34
+ gem 'formal'
35
+ gem 'rdiscount'
32
36
  ```
33
37
 
34
- ## Usage
38
+ # Usage
35
39
 
36
- This is a rails generator so run:
40
+ ## For static pages (the CMS)
37
41
 
38
42
  ```bash
39
- $ rails generate buildybuild:cms
43
+ $ rails generate buildybuild:cms
40
44
 
41
45
  # you can pass a name for the generated resource. Default is "page" i.e.:
42
46
 
43
47
  $ rails generate buildybuild:cms static_page
44
48
  ```
45
49
 
46
-
47
50
  This will create the following files:
48
51
 
49
52
  - app/models/page.rb
@@ -57,13 +60,13 @@ This will create the following files:
57
60
  and appends the following to the bottom of your routes file:
58
61
 
59
62
  ```ruby
60
- resources :pages, only: [:new, :create]
63
+ resources :pages, only: [:new, :create]
61
64
 
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
65
+ #keep these at the bottom of your file. They should be the last routes.
66
+ get "/:slug", to: "pages#show", as: :slug
67
+ get "/:slug/edit", to: "pages#edit", as: :edit_slug
68
+ put "/:slug", to: "pages#update", as: :slug
69
+ post "/:slug", to: "pages#destroy", as: :slug
67
70
  ```
68
71
 
69
72
  ### Next
@@ -71,12 +74,14 @@ and appends the following to the bottom of your routes file:
71
74
  run the migration
72
75
 
73
76
  ```bash
74
- rake db:migrate
77
+ $ rake db:migrate
75
78
  ```
76
79
 
77
- And you're set. Now you can go to ```http://localhost:3000/pages/new``` and see your new Content Management System in action!
80
+ And you're set. Now you can go to ```http://localhost:3000/pages/new``` and see
81
+ your new Content Management System in action!
78
82
 
79
- Or you can create static pages and stick them in ```app/views/pages/```. Then you will automatically have access to the page in your routes.
83
+ Or you can create static pages and stick them in ```app/views/pages/```. Then
84
+ you will automatically have access to the page in your routes.
80
85
 
81
86
  Observe:
82
87
 
@@ -84,7 +89,40 @@ Create a static page called ```app/views/pages/about_us.html.haml```
84
89
 
85
90
  Then automatically have access to ```http://localhost:3000/about-us```.
86
91
 
87
-
92
+ Notice the difference between the underscore "_" in the file name and the dash
93
+ "-" in the url.
94
+
95
+ ## For the active link helper
96
+ This is so you can replace your ```link_to``` helper with ```active_link_to```
97
+ which will add a class of "active" to the link when you're on that page. i.e:
98
+
99
+ ```ruby
100
+ = active_link_to "/about-us", "About"
101
+ ```
102
+ returns the following when the current page is ```/about-us"
103
+ ```html
104
+ <a class="active" href="/about-us">About</a>
105
+ ```
106
+ ### Run
107
+
108
+ ```bash
109
+ $ rails g buildybuild:active_link
110
+ ```
111
+
112
+ This appends the following to the bottom of your ApplicationHelper:
113
+
114
+ ```ruby
115
+ def active_link_to(text, path, options={})
116
+ if /^#{url_for(path)}/ =~ request.path
117
+ options[:class] = "#{options[:class]} active"
118
+ end
119
+ link_to text, path, options
120
+ end
121
+ ```
122
+
123
+ It's kinda small. But cool!
124
+
125
+
88
126
  ## Contributing
89
127
 
90
128
  1. Fork it
data/buildybuild.gemspec CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_runtime_dependency "formal"
21
- gem.add_runtime_dependency "decent_exposure", "2.0.0.rc1"
21
+ gem.add_runtime_dependency "decent_exposure"
22
22
  gem.add_runtime_dependency "haml-rails"
23
23
  gem.add_runtime_dependency "rdiscount"
24
24
 
25
25
  gem.add_development_dependency "railties"
26
+ gem.add_development_dependency "pry"
26
27
  end
data/lib/buildybuild.rb CHANGED
@@ -5,3 +5,4 @@ require 'decent_exposure'
5
5
  require 'rdiscount'
6
6
  require 'formal'
7
7
  require 'generators/buildybuild/cms/cms_generator'
8
+ require 'generators/buildybuild/active_link/active_link_generator'
@@ -1,3 +1,3 @@
1
1
  module Buildybuild
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,18 @@
1
+ module Buildybuild
2
+ class ActiveLinkGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ def add_active_link_helper
5
+ insert_into_file(
6
+ "app/helpers/application_helper.rb",
7
+ helper_method, before: /^end\n*$/
8
+ )
9
+ end
10
+
11
+ private
12
+
13
+ def helper_method
14
+ File.read(File.join(self.class.source_root, "active_link_helper.rb"))
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ def active_link_to(text, path, options={})
2
+ if /^#{url_for(path)}/ =~ request.path
3
+ options[:class] = "#{options[:class]} active"
4
+ end
5
+ link_to text, path, options
6
+ end
7
+
@@ -26,7 +26,7 @@ module Buildybuild
26
26
  end
27
27
 
28
28
  def add_routes
29
- insert_into_file "config/routes.rb", generated_routes, before: /end\n*$/
29
+ insert_into_file "config/routes.rb", generated_routes, before: /^end\n*$/
30
30
  end
31
31
 
32
32
  private
@@ -42,7 +42,6 @@ module Buildybuild
42
42
  post "/:slug", to: "pages#destroy", as: :slug\n)
43
43
  end
44
44
 
45
-
46
45
  def file_name
47
46
  model_name.underscore
48
47
  end
@@ -63,6 +62,10 @@ module Buildybuild
63
62
  klasses.downcase
64
63
  end
65
64
 
65
+ def table_names
66
+ klasses.pluralize.underscore
67
+ end
68
+
66
69
  def controller_name
67
70
  "#{file_name.pluralize}Controller".camelize
68
71
  end
@@ -1,6 +1,6 @@
1
1
  class Create<%= klasses %> < ActiveRecord::Migration
2
2
  def change
3
- create_table :<%= table_name %> do |t|
3
+ create_table :<%= table_names %> do |t|
4
4
  t.string :name
5
5
  t.string :slug
6
6
  t.text :body
@@ -1,8 +1,8 @@
1
- class <%= klass %>
1
+ class <%= klass %> < ActiveRecord::Base
2
2
 
3
3
  attr_accessible :body, :name, :slug
4
4
 
5
- default_scope order('created_at DESC, updated_at DESC')\n
5
+ default_scope order('created_at DESC, updated_at DESC')
6
6
 
7
7
  validates_uniqueness_of :name
8
8
 
@@ -1,5 +1,3 @@
1
- %h1= <%= file_name %>.name.titleize
2
-
3
1
  %nav.actions
4
2
  = link_to "edit", edit_slug_path(<%= file_name %>.slug)
5
3
  |
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class BuildybuildActiveLinkGeneratorTest < Rails::Generators::TestCase
4
+ tests Buildybuild::ActiveLinkGenerator
5
+ destination File.expand_path("../../../../tmp", File.dirname(__FILE__))
6
+ setup :prepare_destination
7
+
8
+ test "ApplicationHelper is updated" do
9
+ #create the file in the test so we can insert into it.
10
+ generator.create_file("app/helpers/application_helper.rb", "module ApplicationHelper \n\nend")
11
+ generator.add_active_link_helper
12
+ assert_file "app/helpers/application_helper.rb", / def active_link_to\(text, path, options=\{\}\)/
13
+ end
14
+
15
+ end
@@ -30,7 +30,7 @@ class BuildybuildCmsGeneratorTest < Rails::Generators::TestCase
30
30
 
31
31
  test "routes are updated" do
32
32
  #create the file in the test so we can insert into it.
33
- generator.create_file("config/routes.rb", "class Routes \n\n end")
33
+ generator.create_file("config/routes.rb", "class Routes \n\nend")
34
34
  generator.add_routes
35
35
  assert_file "config/routes.rb", /get "\/:slug", to: "pages#show", as: :slug/
36
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildybuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-08 00:00:00.000000000Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: formal
16
- requirement: &70209595599460 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,31 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70209595599460
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: decent_exposure
27
- requirement: &70209595596860 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - =
35
+ - - ! '>='
31
36
  - !ruby/object:Gem::Version
32
- version: 2.0.0.rc1
37
+ version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70209595596860
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: haml-rails
38
- requirement: &70209595595400 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70209595595400
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rdiscount
49
- requirement: &70209595593440 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,31 @@ dependencies:
54
69
  version: '0'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70209595593440
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: railties
60
- requirement: &70209595592240 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
61
97
  none: false
62
98
  requirements:
63
99
  - - ! '>='
@@ -65,7 +101,12 @@ dependencies:
65
101
  version: '0'
66
102
  type: :development
67
103
  prerelease: false
68
- version_requirements: *70209595592240
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
69
110
  description: Generators for adding a CMS your site
70
111
  email:
71
112
  - dev@hashrocket.com
@@ -81,6 +122,8 @@ files:
81
122
  - buildybuild.gemspec
82
123
  - lib/buildybuild.rb
83
124
  - lib/buildybuild/version.rb
125
+ - lib/generators/buildybuild/active_link/active_link_generator.rb
126
+ - lib/generators/buildybuild/active_link/templates/active_link_helper.rb
84
127
  - lib/generators/buildybuild/cms/cms_generator.rb
85
128
  - lib/generators/buildybuild/cms/templates/cms_controller.rb
86
129
  - lib/generators/buildybuild/cms/templates/cms_edit_view.html.haml
@@ -89,6 +132,7 @@ files:
89
132
  - lib/generators/buildybuild/cms/templates/cms_model.rb
90
133
  - lib/generators/buildybuild/cms/templates/cms_new_view.html.haml
91
134
  - lib/generators/buildybuild/cms/templates/cms_show_view.html.haml
135
+ - test/generators/buildybuild/active_link/active_link_generator_test.rb
92
136
  - test/generators/buildybuild/cms/cms_generator_test.rb
93
137
  - test/test_helper.rb
94
138
  homepage: https://github.com/mrmicachooper/buildybuild
@@ -111,10 +155,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
155
  version: '0'
112
156
  requirements: []
113
157
  rubyforge_project:
114
- rubygems_version: 1.8.10
158
+ rubygems_version: 1.8.24
115
159
  signing_key:
116
160
  specification_version: 3
117
161
  summary: Create a cms that is not behind the scenes
118
162
  test_files:
163
+ - test/generators/buildybuild/active_link/active_link_generator_test.rb
119
164
  - test/generators/buildybuild/cms/cms_generator_test.rb
120
165
  - test/test_helper.rb