@@ -64,43 +64,35 @@ module LinkHelper
64
64
def path_prefix
65
65
"../" * depth
66
66
end
67
-
68
- def path_to ( obj , methodized = false )
69
- path_prefix << raw_path_to ( obj , methodized )
70
- end
71
67
72
- def raw_path_to ( obj , methodized = false )
73
- return "#{ obj . name . downcase } /" if obj . is_a? ( Documentation ::Section )
74
-
75
- path = [ obj . section . name . downcase ] . concat ( obj . namespace_string . downcase . split ( '.' ) ) . join ( "/" )
76
- if obj . is_a? ( Documentation ::InstanceMethod ) || obj . is_a? ( Documentation ::InstanceProperty )
77
- "#{ path } /prototype/#{ obj . id . downcase } /"
78
- elsif obj . is_a? ( Documentation ::KlassMethod )
79
- methodized ? "#{ path } /prototype/#{ obj . id . downcase } /" : "#{ path } /#{ obj . id . downcase } /"
80
- else
81
- "#{ path } /#{ obj . id . downcase } /"
82
- end
68
+ def path_to ( obj )
69
+ path = path_prefix << raw_path_to ( obj ) . join ( '/' )
70
+ Website . pretty_urls? ? "#{ path } " : "#{ path } /index.html"
83
71
end
84
72
85
- # deprecated
86
- def path_to_section ( obj )
87
- "#{ obj . name . downcase } /"
73
+ def raw_path_to ( obj )
74
+ result = [ ]
75
+ begin
76
+ result << obj . name . downcase . sub ( ' section' , '' ) . gsub ( '$' , 'dollar' )
77
+ if obj . is_a? ( Models ::InstanceMethod ) || obj . is_a? ( Models ::InstanceProperty )
78
+ result << 'prototype'
79
+ end
80
+ obj = obj . parent
81
+ end while obj . respond_to? ( :name )
82
+ result . reverse
88
83
end
89
-
90
- def section_from_name ( name )
91
- root . sections . find { |section | section . name == name }
92
- end
93
84
94
85
def auto_link ( obj , options = { } )
95
86
if obj . is_a? ( String )
96
87
original = obj
97
- obj = root . find_by_name ( obj )
88
+ obj = root . find ( obj )
98
89
return original unless obj
99
90
end
100
91
name = options . delete ( :name ) == :short ? obj . name : obj . full_name
101
- type = obj . is_a? ( Documentation ::KlassMethod ) && options [ :methodized ] ? 'instance method' : obj . type
102
- path = path_to ( obj , options . delete ( :methodized ) )
103
- link_to ( name , path , { :title => "#{ obj . full_name } (#{ type } )" } . merge ( options ) )
92
+ path = path_to ( obj )
93
+ title = obj . full_name
94
+ title = "#{ title } (#{ obj . type } )" unless obj . type == 'section'
95
+ link_to ( name , path , { :title => title } . merge ( options ) )
104
96
end
105
97
106
98
def auto_link_code ( obj , options = { } )
@@ -110,11 +102,11 @@ def auto_link_code(obj, options = {})
110
102
def auto_link_content ( content )
111
103
return '' if content . nil?
112
104
content . gsub! ( /\[ \[ ([a-zA-Z]+)\s +section\] \] / ) do |m |
113
- result = auto_link ( section_from_name ( $1) , :name => :long )
105
+ result = auto_link ( root . find ( $1) , :name => :long )
114
106
result
115
107
end
116
108
content . gsub ( /\[ \[ ([a-zA-Z$\. #]+)(?:\s +([^\] ]+))?\] \] / ) do |m |
117
- if doc_instance = root . find_by_name ( $1)
109
+ if doc_instance = root . find ( $1)
118
110
$2 ? link_to ( $2, path_to ( doc_instance ) ) : auto_link_code ( doc_instance , :name => :long )
119
111
else
120
112
$1
@@ -152,101 +144,104 @@ def methodize_full_name(obj)
152
144
obj . full_name . sub ( /\. ([^.]+)$/ , '#\1' )
153
145
end
154
146
155
- def method_synopsis ( object , methodized = false )
147
+ def method_synopsis ( object )
156
148
result = [ ]
157
- object . ebnf_expressions . each do |ebnf |
158
- if object . is_a? ( Documentation ::Constructor )
159
- result << "#{ object . full_name } #{ ebnf . args . text_value } "
160
- else
161
- types = auto_link_types ( ebnf . returns , :name => :long ) . join ( ' | ' )
162
- if object . is_a? ( Documentation ::KlassMethod ) && object . methodized? && methodized
163
- result << "#{ methodize_signature ( ebnf . signature ) } → #{ types } "
164
- else
165
- result << "#{ ebnf . signature } → #{ types } "
166
- end
149
+ object . signatures . each do |signature |
150
+ if return_value = signature . return_value
151
+ types = auto_link_types ( return_value , :name => :long ) . join ( ' | ' )
152
+ result << "#{ signature . name } → #{ types } "
153
+ else # Constructors
154
+ result << signature . name
167
155
end
168
156
end
169
157
result
170
158
end
171
159
172
160
def breadcrumb ( obj , options )
173
161
result = [ ]
174
- original_obj = obj
175
162
begin
176
163
result << auto_link ( obj , options )
177
- end while obj = obj . namespace
178
- unless original_obj . is_a? ( Documentation ::Section )
179
- result << auto_link ( original_obj . section , options )
180
- end
164
+ obj = obj . parent
165
+ end until obj . is_a? ( Models ::Root )
181
166
result . reverse!
182
167
end
183
168
end
184
169
185
170
module MenuHelper
171
+ NODES = [
172
+ :namespaces ,
173
+ :classes ,
174
+ :mixins ,
175
+ :utilities
176
+ ]
177
+ LEAVES = [
178
+ :constants ,
179
+ :class_methods ,
180
+ :class_properties ,
181
+ :instance_methods ,
182
+ :instance_properties
183
+ ]
184
+
186
185
def menu ( obj )
187
186
html = menu_item ( obj , :name => :long )
188
187
189
- if !obj . children . empty?
190
- list_items = obj . children . map { |n | menu ( n ) } . join ( "\n " )
191
- li_class_names = obj . type == "section" ? "menu-section" : ""
192
- html << content_tag ( :ul , list_items , :class => li_class_names )
193
- elsif obj == doc_instance && obj . respond_to? ( :constants )
194
- html << submenu ( obj )
195
- elsif doc_instance && doc_instance . respond_to? ( :namespace )
196
- namespace = doc_instance . namespace
197
- html << submenu ( namespace ) if namespace == obj && obj . respond_to? ( :constants )
188
+ html << node_submenu ( obj )
189
+
190
+ if obj == doc_instance && obj . respond_to? ( :constants )
191
+ html << leaf_submenu ( obj )
192
+ elsif doc_instance && doc_instance . respond_to? ( :parent )
193
+ parent = doc_instance . parent
194
+ html << leaf_submenu ( parent ) if parent == obj && obj . respond_to? ( :constants )
198
195
end
199
196
200
197
content_tag ( :li , html )
201
198
end
202
199
200
+ def node_submenu ( obj )
201
+ children = [ ]
202
+
203
+ NODES . each do |prop |
204
+ children . concat ( obj . send ( prop ) ) if obj . respond_to? ( prop )
205
+ end
206
+
207
+ list_items = children . sort . map { |item | menu ( item ) } . join ( "\n " )
208
+ li_class_names = obj . type == "section" ? "menu-section" : ""
209
+ content_tag ( :ul , list_items , :class => li_class_names )
210
+ end
211
+
203
212
def menu_item ( obj , options = { } )
204
213
options = options . dup
205
214
options [ :class ] = class_names_for ( obj , options )
206
215
content_tag ( :div , auto_link ( obj , options ) , :class => 'menu-item' )
207
216
end
208
217
209
- def submenu ( obj )
218
+ def leaf_submenu ( obj )
210
219
items = [ ]
211
220
if obj . respond_to? ( :constructor ) && obj . constructor
212
221
items << content_tag ( :li , menu_item ( obj . constructor , :name => :short ) )
213
222
end
214
- [ :constants ,
215
- :klass_methods ,
216
- :klass_properties ,
217
- ] . each do |prop |
218
- obj . send ( prop ) . map { |item | items << content_tag ( :li , menu_item ( item , :name => :short ) ) }
219
- end
220
- instance_methods = obj . instance_methods . dup
221
- methodized_methods = obj . klass_methods . select { |m | m . methodized? }
222
- instance_methods . concat ( methodized_methods )
223
- instance_methods = instance_methods . sort_by { |e | e . name }
224
- instance_methods . map do |item |
225
- items << content_tag ( :li , menu_item ( item , :name => :short , :methodized => true ) )
223
+ LEAVES . each do |prop |
224
+ if obj . respond_to? ( prop )
225
+ obj . send ( prop ) . sort! . map do |item |
226
+ items << content_tag ( :li , menu_item ( item , :name => :short ) )
227
+ end
228
+ end
226
229
end
227
- obj . instance_properties . map { |item | items << content_tag ( :li , menu_item ( item , :name => :short ) ) }
228
-
229
230
content_tag ( :ul , items . join ( "\n " ) )
230
231
end
231
232
232
233
def class_names_for ( obj , options = { } )
233
234
classes = [ ]
234
- if obj . is_a? ( Documentation ::KlassMethod ) && obj . methodized? && options [ :methodized ]
235
- classes << 'instance-method'
236
- else
237
- classes << obj . type . gsub ( /\s +/ , '-' )
238
- end
235
+ classes << obj . type . gsub ( /\s +/ , '-' )
239
236
classes << "deprecated" if obj . deprecated?
240
237
if doc_instance
241
238
if obj == doc_instance
242
239
classes << "current"
243
- elsif doc_instance . namespace == obj ||
244
- obj . descendants . include? ( doc_instance ) ||
245
- obj . descendants . include? ( doc_instance . namespace )
240
+ elsif obj . ancestor_of? ( doc_instance )
246
241
classes << "current-parent"
247
242
end
248
243
end
249
- classes . join ( " " )
244
+ classes . join ( ' ' )
250
245
end
251
246
end
252
247
end
0 commit comments