mirror of
https://github.com/github/rails.git
synced 2026-01-12 08:08:31 -05:00
Compare commits
3 Commits
github26
...
optimize-u
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbe129af02 | ||
|
|
bf71aa30d2 | ||
|
|
0928c2bf4f |
@@ -138,8 +138,13 @@ module ActionController
|
||||
end
|
||||
end
|
||||
|
||||
def named_helper_module_eval(code, *args)
|
||||
@module.module_eval(code, *args)
|
||||
def named_helper_module_eval(code)
|
||||
file, line = caller.first.split(":")
|
||||
compile_option = RubyVM::InstructionSequence.compile_option
|
||||
RubyVM::InstructionSequence.compile_option = compile_option.merge(:trace_instruction => false)
|
||||
@module.module_eval(code, file, line.to_i + 1)
|
||||
ensure
|
||||
RubyVM::InstructionSequence.compile_option = compile_option
|
||||
end
|
||||
|
||||
def define_hash_access(route, name, kind, options)
|
||||
@@ -196,6 +201,40 @@ module ActionController
|
||||
protected :#{selector} # protected :users_url
|
||||
end_eval
|
||||
helpers << selector
|
||||
|
||||
if kind == :path
|
||||
define_fast_url_helper(selector, route, name)
|
||||
end
|
||||
end
|
||||
|
||||
def define_fast_url_helper(selector, route, name)
|
||||
dynamic_segments = route.segments.grep(DynamicSegment)
|
||||
|
||||
return if dynamic_segments.any?(&:optional?) # TODO - maybe exclude optional format
|
||||
|
||||
helper_arguments = dynamic_segments.map { |route_argument|
|
||||
"arg_#{route_argument.key}"
|
||||
}
|
||||
|
||||
route_segments = route.segments.dup
|
||||
|
||||
if route_segments.size > 1 && route_segments.last.is_a?(DividerSegment) && route_segments.last.optional?
|
||||
route_segments.pop
|
||||
end
|
||||
|
||||
string_segments = route_segments.map { |segment|
|
||||
if segment.is_a?(StaticSegment)
|
||||
segment.value.inspect
|
||||
else
|
||||
'"#{URI::DEFAULT_PARSER.escape(arg_%s.to_s, ActionController::Routing::Segment::UNSAFE_PCHAR)}"' % segment.key
|
||||
end
|
||||
}
|
||||
|
||||
named_helper_module_eval <<-"RUBY"
|
||||
def fast_#{selector}(#{helper_arguments.join(", ")})
|
||||
#{string_segments.join(" ")}
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user