Class: Copy::Router
- Inherits:
-
Object
- Object
- Copy::Router
- Defined in:
- lib/copy/router.rb
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(path, views) ⇒ Router
constructor
A new instance of Router.
- #layout ⇒ Object
- #renderer ⇒ Object
- #success? ⇒ Boolean
- #template ⇒ Object
- #template_file ⇒ Object
Constructor Details
#initialize(path, views) ⇒ Router
Returns a new instance of Router.
3 4 5 6 |
# File 'lib/copy/router.rb', line 3 def initialize(path, views) @path = determine_path(path) @views = views end |
Instance Method Details
#format ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/copy/router.rb', line 8 def format @format ||= if @path.index('.') @path.split('.').last.to_sym else :html end end |
#layout ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/copy/router.rb', line 32 def layout @layout ||= if format == :html && File.exists?(File.join(@views, "layout.html.#{renderer}")) :'layout.html' else false end end |
#renderer ⇒ Object
24 25 26 |
# File 'lib/copy/router.rb', line 24 def renderer @renderer ||= template_file.split('.').last.to_sym end |
#success? ⇒ Boolean
40 41 42 |
# File 'lib/copy/router.rb', line 40 def success? template_file && renderer && template end |
#template ⇒ Object
28 29 30 |
# File 'lib/copy/router.rb', line 28 def template @template ||= template_file.gsub(%r{^#{@views}\/*}, '').gsub(%r{.#{renderer}$}, '').to_sym end |
#template_file ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/copy/router.rb', line 16 def template_file @template_file ||= if file = Dir.glob(File.join(@views, "#{path_with_format}*")).first file elsif index = Dir.glob(File.join(@views, path_without_format, "index.#{format}*")).first index end end |