Module: NanDoc::DataSource::ItemMethods
- Included in:
- NanDoc::DataSource, Orphanage
- Defined in:
- lib/nandoc/hacks/data-source.rb
Instance Method Summary collapse
- #dot_dot_has?(str) ⇒ Boolean
- #dot_dot_strip(str) ⇒ Object
- #dot_dot_strip_assert(str) ⇒ Object
-
#find_parent(item_identifier) ⇒ Object
must have @items.
- #identifier_bare_rootname(identifier) ⇒ Object
- #identifier_bare_rootname_assert(identifier) ⇒ Object
- #parent_identifier(identifier) ⇒ Object
- #site_root ⇒ Object
-
#slash_strip(identifier) ⇒ Object
exactly one leading and one trailing slash.
- #slash_strip_assert(identifier) ⇒ Object
Instance Method Details
#dot_dot_has?(str) ⇒ Boolean
227 228 229 |
# File 'lib/nandoc/hacks/data-source.rb', line 227 def dot_dot_has? str /\A\.\./ =~ str end |
#dot_dot_strip(str) ⇒ Object
230 231 232 |
# File 'lib/nandoc/hacks/data-source.rb', line 230 def dot_dot_strip str /\A\.\.(.*)\Z/ =~ str and $1 end |
#dot_dot_strip_assert(str) ⇒ Object
233 234 235 236 |
# File 'lib/nandoc/hacks/data-source.rb', line 233 def dot_dot_strip_assert str dot_dot_strip(str) or fail("hack fail: no leading dot dot: #{str.inspect}") end |
#find_parent(item_identifier) ⇒ Object
must have @items. make public if u need it
202 203 204 205 206 |
# File 'lib/nandoc/hacks/data-source.rb', line 202 def find_parent item_identifier parent_path = parent_identifier(item_identifier) parent = @items.find { |p| p.identifier == parent_path } parent end |
#identifier_bare_rootname(identifier) ⇒ Object
207 208 209 |
# File 'lib/nandoc/hacks/data-source.rb', line 207 def identifier /\A\/([^\/]+)\// =~ identifier and $1 end |
#identifier_bare_rootname_assert(identifier) ⇒ Object
210 211 212 213 |
# File 'lib/nandoc/hacks/data-source.rb', line 210 def identifier (identifier) or fail("hack fail: couldn't find rootname for #{identifier.inspect}") end |
#parent_identifier(identifier) ⇒ Object
221 222 223 |
# File 'lib/nandoc/hacks/data-source.rb', line 221 def parent_identifier identifier identifier.sub(/[^\/]+\/$/, '') end |
#site_root ⇒ Object
224 225 226 |
# File 'lib/nandoc/hacks/data-source.rb', line 224 def site_root @site_root ||= @items.find{|x| x.identifier == '/' } end |
#slash_strip(identifier) ⇒ Object
exactly one leading and one trailing slash
215 216 217 |
# File 'lib/nandoc/hacks/data-source.rb', line 215 def slash_strip identifier /\A\/(.+)\/\Z/ =~ identifier and $1 end |
#slash_strip_assert(identifier) ⇒ Object
218 219 220 |
# File 'lib/nandoc/hacks/data-source.rb', line 218 def slash_strip_assert identifier slash_strip(identifier) or fail("hack fail: #{identifier}") end |