提交 c825e9a5 编写于 作者: C Carlos Antonio da Silva 提交者: Santiago Pastorino

Create generators http_only! setup and hide some common namespaces for now

[Carlos Antonio da Silva & Santiago Pastorino]
上级 124838b5
...@@ -44,14 +44,14 @@ module Configuration ...@@ -44,14 +44,14 @@ module Configuration
# Cookies, Session and Flash, BestStandardsSupport, and MethodOverride. You # Cookies, Session and Flash, BestStandardsSupport, and MethodOverride. You
# can always add any of them later manually if you want. # can always add any of them later manually if you want.
class MiddlewareStackProxy class MiddlewareStackProxy
attr_reader :http_only
alias :http_only? :http_only
def initialize def initialize
@operations = [] @operations = []
@http_only = false @http_only = false
end end
attr_reader :http_only
alias :http_only? :http_only
def http_only! def http_only!
@http_only = true @http_only = true
end end
...@@ -90,6 +90,9 @@ class Generators #:nodoc: ...@@ -90,6 +90,9 @@ class Generators #:nodoc:
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
attr_reader :hidden_namespaces attr_reader :hidden_namespaces
attr_reader :http_only
alias :http_only? :http_only
def initialize def initialize
@aliases = Hash.new { |h,k| h[k] = {} } @aliases = Hash.new { |h,k| h[k] = {} }
@options = Hash.new { |h,k| h[k] = {} } @options = Hash.new { |h,k| h[k] = {} }
...@@ -97,6 +100,7 @@ def initialize ...@@ -97,6 +100,7 @@ def initialize
@templates = [] @templates = []
@colorize_logging = true @colorize_logging = true
@hidden_namespaces = [] @hidden_namespaces = []
@http_only = false
end end
def initialize_copy(source) def initialize_copy(source)
...@@ -110,6 +114,10 @@ def hide_namespace(namespace) ...@@ -110,6 +114,10 @@ def hide_namespace(namespace)
@hidden_namespaces << namespace @hidden_namespaces << namespace
end end
def http_only!
@http_only = true
end
def method_missing(method, *args) def method_missing(method, *args)
method = method.to_s.sub(/=$/, '').to_sym method = method.to_s.sub(/=$/, '').to_sym
......
...@@ -68,6 +68,7 @@ def self.configure!(config) #:nodoc: ...@@ -68,6 +68,7 @@ def self.configure!(config) #:nodoc:
templates_path.concat config.templates templates_path.concat config.templates
templates_path.uniq! templates_path.uniq!
hide_namespaces(*config.hidden_namespaces) hide_namespaces(*config.hidden_namespaces)
http_only! if config.http_only?
end end
def self.templates_path def self.templates_path
...@@ -104,6 +105,11 @@ def self.no_color! ...@@ -104,6 +105,11 @@ def self.no_color!
Thor::Base.shell = Thor::Shell::Basic Thor::Base.shell = Thor::Shell::Basic
end end
# Configure generators for http only
def self.http_only!
hide_namespaces "assets", "css", "js", "session_migration"
end
# Track all generators subclasses. # Track all generators subclasses.
def self.subclasses def self.subclasses
@subclasses ||= [] @subclasses ||= []
...@@ -235,7 +241,7 @@ def self.help(command = 'generate') ...@@ -235,7 +241,7 @@ def self.help(command = 'generate')
rails.delete("plugin_new") rails.delete("plugin_new")
print_list("rails", rails) print_list("rails", rails)
hidden_namespaces.each {|n| groups.delete(n.to_s) } hidden_namespaces.each { |n| groups.delete(n.to_s) }
groups.sort.each { |b, n| print_list(b, n) } groups.sort.each { |b, n| print_list(b, n) }
end end
......
...@@ -213,4 +213,28 @@ def test_hide_namespace ...@@ -213,4 +213,28 @@ def test_hide_namespace
Rails::Generators.hide_namespace("special:namespace") Rails::Generators.hide_namespace("special:namespace")
assert Rails::Generators.hidden_namespaces.include?("special:namespace") assert Rails::Generators.hidden_namespaces.include?("special:namespace")
end end
def test_http_only_hides_generators
generators = %w(assets js css session_migration)
generators.each do |generator|
assert !Rails::Generators.hidden_namespaces.include?(generator)
end
with_http_only! do
generators.each do |generator|
assert Rails::Generators.hidden_namespaces.include?(generator),
"http only should hide #{generator} generator"
end
end
end
private
def with_http_only!
Rails::Generators.http_only!
yield
ensure
Rails::Generators.instance_variable_set(:@http_only, false)
end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册