rails-brochure 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Dan Hixon
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.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ Rails Brochure
2
+ ============
3
+
4
+ Rails engine for brochure pages. Similar to High Voltage but with named routes.
5
+
6
+ Brochure pages are the semi-static pages like "home", "about us", "FAQ", "pricing", "contact us", etc.
7
+
8
+ Most of the designers I have worked with really appreciate the power and convenience this plugin provides. They are able to simply create erb files in folders like they are used to with static html or php and it just works. No futzing with routes, controllers etc.
9
+
10
+ Installation
11
+ ------------
12
+
13
+ Rails 3 required.
14
+
15
+ Include in your Gemfile:
16
+
17
+ gem "rails-brochure"
18
+
19
+ Don't forget to install:
20
+
21
+ $ bundle install
22
+
23
+ You can install from the command line as well:
24
+
25
+ $ sudo gem install rails-brochure
26
+
27
+ Usage
28
+ -----
29
+
30
+ Write your static pages and put them in the RAILS_ROOT/app/views/home directory.
31
+
32
+ mkdir app/views/home
33
+ touch app/views/home/about.html.erb
34
+
35
+ After putting something interesting there, a named route is created and you can link to it from anywhere in your app with:
36
+
37
+ link_to "About", about_url
38
+ link_to "About", about_path
39
+
40
+ You can also create content in sub directories like this:
41
+
42
+ mkdir app/views/home/about
43
+ touch app/views/home/about/company
44
+
45
+ This will create a named route about_company:
46
+
47
+ link_to "Company", about_company_url
48
+ link_to "Company", about_company_path
49
+
50
+ Once you have an index template you may want to add this route to your config/routes.rb:
51
+
52
+ root :to => "home#index"
53
+
54
+ Name Routes?
55
+ --------
56
+
57
+ Named routes are good because if you change a page name (about.html.erb to about_us.html.erb) without updating the links you'll get failing tests:
58
+
59
+ ActionView::TemplateError: undefined local variable or method `about_path'
60
+
61
+
62
+ Override
63
+ --------
64
+
65
+ Some reasons you may want to override:
66
+
67
+ * Need to grab some data from a database or something.
68
+ * Need authentication around some pages
69
+ * Need to render different layouts for different pages.
70
+
71
+ Create a HomeController of your own:
72
+
73
+ rails generate controller home
74
+
75
+ Then just add in the actions you want to behave differently:
76
+
77
+ class HomeController < ApplicationController
78
+ before_filter :require_user, :only => :private_info
79
+
80
+ def pricing
81
+ @prices = Price.all
82
+ end
83
+
84
+ def index
85
+ # index page has it's own layout html
86
+ render :layout => false
87
+ end
88
+
89
+ def private_info
90
+ @info = current_user.private_info
91
+ end
92
+
93
+ end
94
+
95
+ Enjoy!
96
+
97
+ License
98
+ -------
99
+
100
+ Rails Brochure is Copyright © 2010-2011 Dan Hixon. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -0,0 +1,3 @@
1
+ class HomeController < ApplicationController
2
+
3
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ Rails::Brochure::HomeContent.templates.each do |pg|
3
+ match "/#{pg}" => "home##{pg}", :as => pg.gsub('/','_').to_sym
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate brochure
6
+
7
+ This will create:
8
+ app/views/home
9
+ app/views/home/index.html.erb
10
+ app/views/home/about.html.erb
@@ -0,0 +1,3 @@
1
+ class BrochureGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ end
@@ -0,0 +1,2 @@
1
+ <h1>home#about</h1>
2
+ find me in app/views/home/about.html.erb
@@ -0,0 +1,2 @@
1
+ <h1>home#index</h1>
2
+ find me in app/views/home/index.html.erb
@@ -1,4 +1,3 @@
1
- require File.dirname(__FILE__) + '/rails-brochure/home_content'
2
- require File.dirname(__FILE__) + '/rails-brochure/route_reloader'
3
- require File.dirname(__FILE__) + '/rails-brochure/engine'
4
-
1
+ require File.expand_path(File.dirname(__FILE__)) + '/rails-brochure/home_content'
2
+ require File.expand_path(File.dirname(__FILE__)) + '/rails-brochure/route_reloader'
3
+ require File.expand_path(File.dirname(__FILE__)) + '/rails-brochure/engine'
@@ -0,0 +1,11 @@
1
+ # Engine injects some middleware to reload
2
+ # routes if new files habe been added
3
+ module Rails
4
+ module Brochure
5
+ class Engine < Rails::Engine
6
+ initializer "brochure routes" do |app|
7
+ app.middleware.use "Rails::Brochure::RouteReloader"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Rails
2
+ module Brochure
3
+ class HomeContent
4
+ HOME_FOLDER_PATH = "app/views/home/"
5
+ def self.newest
6
+ HomeContent.files.map { |f| File.new(f) }.sort { |a,b| a.ctime <=> b.ctime }.map { |f| f.ctime }.last
7
+ end
8
+ def self.files
9
+ Dir.glob("#{HOME_FOLDER_PATH}**/*.html.*")
10
+ end
11
+ def self.templates
12
+ HomeContent.files.map do |f|
13
+ f.gsub(/(#{HOME_FOLDER_PATH}|.html.\w+)/,"")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module Rails
2
+ module Brochure
3
+ class RouteReloader
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+ def call(env)
8
+ reload_routes if new_content?
9
+ @app.call(env)
10
+ end
11
+ def reload_routes
12
+ # we must touch the routes file in order for it to be reloaded
13
+ FileUtils.touch("config/routes.rb")
14
+ Rails.application.reload_routes!
15
+ Rails.logger.info "ROUTES RELOADED by rails-brochure"
16
+ end
17
+ def new_content?
18
+ HomeContent.newest > last_route_change
19
+ end
20
+ def last_route_change
21
+ File.mtime("config/routes.rb")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Brochure
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -9,8 +9,10 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Dan Hixon"]
10
10
  s.email = ["danhixon@gmail.com"]
11
11
  s.homepage = "http://github.com/danhixon/rails-brochure"
12
- s.summary = %q{Rails Plugin for hosting static content files a-la-php with named routes.}
13
- s.description = %q{Rails Plugin for hosting static content files a-la-php with named routes. It is a lot like high voltage but you get named routes and '/pages' is not part of your routes.}
12
+ s.summary = %q{Rails engine for brochure pages. Similar to High Voltage but with named routes.}
13
+ s.description = %q{Rails engine for brochure pages. Similar to High Voltage but with named routes.
14
+ Brochure pages are the semi-static pages like "home", "about us", "FAQ", "pricing", "contact us", etc.
15
+ Most of the designers I have worked with really appreciate the power and convenience this plugin provides. They are able to simply create erb files in folders like they are used to with static html or php and it just works. No futzing with routes, controllers etc.}
14
16
 
15
17
  s.add_dependency('rails', '>= 3.0.0')
16
18
 
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-brochure
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
4
+ prerelease:
5
+ version: 0.0.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - Dan Hixon
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-01-29 00:00:00 -07:00
13
+ date: 2011-04-01 00:00:00 -07:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,15 +21,13 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
34
24
  version: 3.0.0
35
25
  type: :runtime
36
26
  version_requirements: *id001
37
- description: Rails Plugin for hosting static content files a-la-php with named routes. It is a lot like high voltage but you get named routes and '/pages' is not part of your routes.
27
+ description: |-
28
+ Rails engine for brochure pages. Similar to High Voltage but with named routes.
29
+ Brochure pages are the semi-static pages like "home", "about us", "FAQ", "pricing", "contact us", etc.
30
+ Most of the designers I have worked with really appreciate the power and convenience this plugin provides. They are able to simply create erb files in folders like they are used to with static html or php and it just works. No futzing with routes, controllers etc.
38
31
  email:
39
32
  - danhixon@gmail.com
40
33
  executables: []
@@ -46,8 +39,19 @@ extra_rdoc_files: []
46
39
  files:
47
40
  - .gitignore
48
41
  - Gemfile
42
+ - MIT-LICENSE
43
+ - README.md
49
44
  - Rakefile
45
+ - app/controllers/home_controller.rb
46
+ - config/routes.rb
47
+ - lib/generators/USAGE
48
+ - lib/generators/brochure_generator.rb
49
+ - lib/generators/templates/app/views/home/about.html.erb
50
+ - lib/generators/templates/app/views/home/index.html.erb
50
51
  - lib/rails-brochure.rb
52
+ - lib/rails-brochure/engine.rb
53
+ - lib/rails-brochure/home_content.rb
54
+ - lib/rails-brochure/route_reloader.rb
51
55
  - lib/rails-brochure/version.rb
52
56
  - rails-brochure.gemspec
53
57
  has_rdoc: true
@@ -64,25 +68,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
68
  requirements:
65
69
  - - ">="
66
70
  - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
71
  version: "0"
71
72
  required_rubygems_version: !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ">="
75
76
  - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
77
  version: "0"
80
78
  requirements: []
81
79
 
82
80
  rubyforge_project: rails-brochure
83
- rubygems_version: 1.3.7
81
+ rubygems_version: 1.5.2
84
82
  signing_key:
85
83
  specification_version: 3
86
- summary: Rails Plugin for hosting static content files a-la-php with named routes.
84
+ summary: Rails engine for brochure pages. Similar to High Voltage but with named routes.
87
85
  test_files: []
88
86