class Confluence::Railties::Resolver
Public Instance Methods
find_templates(name, prefix, partial, details)
click to toggle source
# File lib/confluence/railties/resolver.rb, line 6 def find_templates(name, prefix, partial, details) if partial gem_directory = _get_gem_directory prefix partial_path = _get_partial_path name, gem_directory handler = _get_handler_from_nothing source = _get_source_from_path(partial_path) identifier = _get_identifier name, prefix normalized_details = _normalize_details(partial_path, details) _get_templates( source, identifier, handler, normalized_details ) else [] end end
Private Instance Methods
_checks()
click to toggle source
# File lib/confluence/railties/resolver.rb, line 26 def _checks @_checks ||= [ lambda do |not_null| !not_null.nil? end ] end
_get_gem_directory(prefix)
click to toggle source
# File lib/confluence/railties/resolver.rb, line 47 def _get_gem_directory(prefix) return nil if prefix.nil? || prefix.blank? prefixes = prefix.split("/") gem_name = prefixes.first if gem_root_path = Gem.loaded_specs[gem_name].try( :full_gem_path) File.join(gem_root_path, "assets", "html", *prefixes[1..-1]) else nil end end
_get_handler_from_nothing()
click to toggle source
# File lib/confluence/railties/resolver.rb, line 72 def _get_handler_from_nothing ActionView::Template.registered_template_handler("haml") end
_get_identifier(name, prefix)
click to toggle source
# File lib/confluence/railties/resolver.rb, line 76 def _get_identifier(name, prefix) "#{name.hash}-#{prefix.hash}" end
_get_partial_path(name, path)
click to toggle source
This assumes, of course, our gem is built from confluence TODO: throw an error if our gem isn't confluent
# File lib/confluence/railties/resolver.rb, line 60 def _get_partial_path(name, path) return nil if name.nil? || path.nil? names = name.split("/") names.push( "_#{names.pop}" ) File.join(path, *names) end
_get_source_from_path(path)
click to toggle source
# File lib/confluence/railties/resolver.rb, line 67 def _get_source_from_path(path) return nil if path.nil? File.read( path + ".html.haml" ) end
_get_templates( *stuffs )
click to toggle source
# File lib/confluence/railties/resolver.rb, line 34 def _get_templates( *stuffs ) results = _checks.inject(true) do |status, check| stuffs.inject(status) do |mem, stuff| mem && check.call(stuff) end end if results [ActionView::Template.new(stuffs.shift, stuffs.shift, stuffs.shift, stuffs.shift)] else [] end end
_normalize_details( path, details )
click to toggle source
# File lib/confluence/railties/resolver.rb, line 22 def _normalize_details( path, details ) details.merge( :virtual_path => path ) end