Module: YARD::Templates::Helpers::BaseHelper
- Defined in:
- lib/yard-api/templates/helpers/base_helper.rb
Instance Method Summary collapse
- #api_options ⇒ Object
- #get_current_route ⇒ Object
- #get_current_routes ⇒ Object
- #linkify_with_api(*args) ⇒ Object (also: #linkify)
- #lookup_appendix(title) ⇒ Object
- #lookup_topic(controller_name) ⇒ Object
- #tag_partial(name, tag, locals = {}) ⇒ Object
Instance Method Details
#api_options ⇒ Object
4 5 6 |
# File 'lib/yard-api/templates/helpers/base_helper.rb', line 4 def () YARD::APIPlugin. end |
#get_current_route ⇒ Object
121 122 123 |
# File 'lib/yard-api/templates/helpers/base_helper.rb', line 121 def get_current_route get_current_routes.first end |
#get_current_routes ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/yard-api/templates/helpers/base_helper.rb', line 112 def get_current_routes controller_name = object.parent.path.underscore controller_name.sub!("_controller", '') unless controller_name.include?('/') action = object.path.sub(/^.*#/, '').sub(/_with_.*$/, '') YARD::Templates::Helpers::RouteHelper.api_methods_for_controller_and_action(controller_name, action) end |
#linkify_with_api(*args) ⇒ Object Also known as: linkify
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/yard-api/templates/helpers/base_helper.rb', line 8 def linkify_with_api(*args) # References to controller actions # # Syntax: api:ControllerName#method_name [TITLE OVERRIDE] # # @example Explicit reference with title defaulting to the action # # @see api:Assignments#create # # => <a href="assignments.html#method.assignments_api.create">create</a> # # @example Inline reference with an overriden title # # Here's a link to absolute {api:Assignments#destroy destruction} # # => <a href="assignments.html#method.assignments_api.destroy">destruction</a> # # @note Action links inside the All Resources section will be relative. if args.first.is_a?(String) && args.first =~ %r{^api:([^#]+)#(.*)} topic, controller = *lookup_topic($1.to_s) if topic html_file = "#{topicize topic.first}.html" action = $2 link_url("#{html_file}#method.#{topicize(controller.name.to_s).sub("_controller", "")}.#{action}", args[1]) else raise "couldn't find API link for #{args.first}" end # References to API objects defined by @object # # Syntax: api:ControllerName:Object+Name [TITLE OVERRIDE] # # @example Explicit resource reference with title defaulting to its name # # @see api:Assignments:Assignment # # => <a href="assignments.html#Assignment">Assignment</a> # # @example Explicit resource reference with an overriden title # # @return api:Assignments:AssignmentOverride An Assignment Override # # => <a href="assignments.html#Assignment">An Assignment Override</a> elsif args.first.is_a?(String) && args.first =~ %r{^api:([^:]+):(.*)} scope_name, resource_name = $1.downcase, $2.gsub('+', ' ') link_url("#{scope_name}.html##{resource_name}", args[1] || resource_name) elsif args.first.is_a?(String) && args.first == 'Appendix:' && args.size > 1 __errmsg = "unable to locate referenced appendix '#{args[1]}'" unless appendix = lookup_appendix(args[1].to_s) raise __errmsg end topic, controller = *lookup_topic(appendix.namespace.to_s) if topic html_file = "#{topicize topic.first}.html" bookmark = "#{appendix.name.to_s.gsub(' ', '+')}-appendix" ret = link_url("#{html_file}##{bookmark}", appendix.title) else raise __errmsg end # A non-API link, delegate to YARD's HTML linker else linkify_without_api(*args) end end |
#lookup_appendix(title) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/yard-api/templates/helpers/base_helper.rb', line 85 def lookup_appendix(title) appendix = nil YARD::APIPlugin.log("Looking up appendix: #{title}") if .verbose if object # try in the object scope appendix = YARD::Registry.at(".appendix.#{object.path}.#{title}") # try in the object's namespace scope if appendix.nil? && object.respond_to?(:namespace) appendix = YARD::Registry.at(".appendix.#{object.namespace.path}.#{title}") end end appendix end |
#lookup_topic(controller_name) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/yard-api/templates/helpers/base_helper.rb', line 72 def lookup_topic(controller_name) controller = nil topic = [:resources].find do |resource, controllers| controllers.detect do |_controller| if _controller.path.to_s == controller_name controller = _controller end end end [ topic, controller ] end |
#tag_partial(name, tag, locals = {}) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/yard-api/templates/helpers/base_helper.rb', line 103 def tag_partial(name, tag, locals={}) [:tag] = tag locals.each_pair { |key, value| [key] = value } out = erb(name) .delete(:tag) locals.keys.each { |key| .delete(key.to_sym) } out end |