nickel-will_static_generator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/rails_generators/USAGE +1 -0
- data/rails_generators/lib/insert_routes.rb +55 -0
- data/rails_generators/templates/page.html.erb +1 -0
- data/rails_generators/templates/page.html.haml +3 -0
- data/rails_generators/templates/pages_controller.rb +51 -0
- data/rails_generators/will_static_generator.rb +57 -0
- metadata +60 -0
@@ -0,0 +1 @@
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Rails::Generator::Commands::Create.class_eval do
|
2
|
+
def route_resource(*resources)
|
3
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
4
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
5
|
+
|
6
|
+
logger.route "map.resource #{resource_list}"
|
7
|
+
unless options[:pretend]
|
8
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
9
|
+
"#{match}\n map.resource #{resource_list}\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def route_name(name, path, route_options)
|
15
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
16
|
+
look_for = "\n map.#{name} '#{path}', #{route_options}"
|
17
|
+
logger.route "map.#{name} '#{path}', #{route_options}"
|
18
|
+
|
19
|
+
unless options[:pretend]
|
20
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
21
|
+
"#{match}\n #{look_for}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
28
|
+
def route_resource(*resources)
|
29
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
30
|
+
look_for = "\n map.resource #{resource_list}\n"
|
31
|
+
logger.route "map.resource #{resource_list}"
|
32
|
+
unless options[:pretend]
|
33
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def route_name(name, path, route_options)
|
38
|
+
look_for = "\n map.#{name} '#{path}', #{route_options}"
|
39
|
+
logger.route "map.#{name} '#{path}', #{route_options}"
|
40
|
+
unless options[:pretend]
|
41
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Rails::Generator::Commands::List.class_eval do
|
47
|
+
def route_resource(*resources)
|
48
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
49
|
+
logger.route "map.resource #{resource_list}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def route_name(name, path, options = {})
|
53
|
+
logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
I'm <strong><%= params[:subpage] || params[:page] %></strong>. Change me.
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class PagesController < ApplicationController
|
2
|
+
verify :params => :page, :only => :show, :redirect_to => :root_path
|
3
|
+
before_filter <%= ":set_locale," if options[:locale] %> :ensure_valid, :only => :show
|
4
|
+
|
5
|
+
# Uncomment if you want cache for static pages
|
6
|
+
# caches_page :show
|
7
|
+
|
8
|
+
def show
|
9
|
+
render :template => <%= options[:subpage] ? "get_template" : "pages/#{current_page}" %>
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
<%- if options[:subpage] -%>
|
14
|
+
["page", "subpage"].each do |method|
|
15
|
+
define_method "current_#{method}" do
|
16
|
+
params[method.to_sym].to_s.downcase
|
17
|
+
end
|
18
|
+
end
|
19
|
+
<%- else -%>
|
20
|
+
def current_page
|
21
|
+
@page ||= params[:page].to_s.downcase
|
22
|
+
end
|
23
|
+
<%- end -%>
|
24
|
+
<%- if options[:locale] -%>
|
25
|
+
|
26
|
+
def set_locale
|
27
|
+
I18n.locale = params[:locale]
|
28
|
+
end
|
29
|
+
<%- end -%>
|
30
|
+
|
31
|
+
def ensure_valid
|
32
|
+
unless template_exists? <%= options[:subpage] ? "get_template" : "pages/#{current_page}" %>
|
33
|
+
redirect_to root_path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
<%- if options[:subpage] %>
|
37
|
+
def get_template
|
38
|
+
["pages", current_page, current_subpage].join('/').chomp('/')
|
39
|
+
end
|
40
|
+
|
41
|
+
<%- end -%>
|
42
|
+
private
|
43
|
+
# Define template_exists? for Rails 2.3 (cause it's deprecated)
|
44
|
+
unless ActionController::Base.private_instance_methods.include? 'template_exists?'
|
45
|
+
def template_exists?(path)
|
46
|
+
self.view_paths.find_template(path, response.template.template_format)
|
47
|
+
rescue ActionView::MissingTemplate
|
48
|
+
false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_routes.rb")
|
2
|
+
|
3
|
+
class WillStaticGenerator < Rails::Generator::Base
|
4
|
+
attr_accessor :files
|
5
|
+
|
6
|
+
def initialize(runtime_args, runtime_options = {})
|
7
|
+
super
|
8
|
+
@files = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def manifest
|
12
|
+
record do |m|
|
13
|
+
m.template "pages_controller.rb", "app/controllers/pages_controller.rb"
|
14
|
+
|
15
|
+
m.directory('app/views/pages')
|
16
|
+
|
17
|
+
@files.each do |file|
|
18
|
+
generate_file(file, m)
|
19
|
+
end
|
20
|
+
|
21
|
+
if options[:locale]
|
22
|
+
m.route_name('page', '/:locale/page/:page', ":controller => 'pages', :action => 'show', :page => nil,
|
23
|
+
:requirements => { :locale => /es|en/ }")
|
24
|
+
else
|
25
|
+
m.route_name('page', '/page/:page', ":controller => 'pages', :action => 'show', :page => nil")
|
26
|
+
end
|
27
|
+
|
28
|
+
if options[:locale] && options[:subpage]
|
29
|
+
m.route_name('subpage', '/:locale/page/:page/:subpage', ":controller => 'pages',
|
30
|
+
:action => 'show', :requirements => { :locale => /es|en/ }")
|
31
|
+
else
|
32
|
+
m.route_name('subpage', '/page/:page/:subpage', ":controller => 'pages',
|
33
|
+
:action => 'show', :requirements => { :locale => /es|en/ }")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def generate_file(file, record)
|
40
|
+
format = options[:haml] ? "haml" : "erb"
|
41
|
+
pages_path = lambda {|f| File.join("app/views/pages", f)}
|
42
|
+
|
43
|
+
if file.include?("/") && !File.exists?(pages_path.call(file))
|
44
|
+
record.directory(pages_path.call(file.split("/").first))
|
45
|
+
end
|
46
|
+
|
47
|
+
record.file("page.html.#{format}", "#{pages_path.call('')}#{file}.html.#{format}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_options!(opt)
|
51
|
+
opt.separator ''
|
52
|
+
opt.separator 'Options:'
|
53
|
+
opt.on("--haml", "Generate views with haml format") { |v| options[:haml] = true }
|
54
|
+
opt.on("--locale", "Generate logic for i18n") { |v| options[:locale] = true }
|
55
|
+
opt.on("--subpage", "Generate logic for subpage's style") { |v| options[:subpage] = true }
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nickel-will_static_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juan Gallego
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-17 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Generators which a page controller generate for static pages
|
17
|
+
email: juan.gallego.iv@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- rails_generators/USAGE
|
26
|
+
- rails_generators/lib
|
27
|
+
- rails_generators/templates
|
28
|
+
- rails_generators/lib/insert_routes.rb
|
29
|
+
- rails_generators/templates/page.html.erb
|
30
|
+
- rails_generators/templates/page.html.haml
|
31
|
+
- rails_generators/templates/pages_controller.rb
|
32
|
+
- rails_generators/will_static_generator.rb
|
33
|
+
has_rdoc: false
|
34
|
+
homepage: http://github.com/nickel/will_static_generator
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: Generators which a page controller generate for static pages
|
59
|
+
test_files: []
|
60
|
+
|