Module: NanDoc::DataSource::ItemMethods

Included in:
NanDoc::DataSource, Orphanage
Defined in:
lib/nandoc/data-source.rb

Instance Method Summary collapse

Instance Method Details

#dot_dot_has?(str) ⇒ Boolean

Returns:

  • (Boolean)


226
227
228
# File 'lib/nandoc/data-source.rb', line 226

def dot_dot_has? str
  /\A\.\./ =~ str
end

#dot_dot_strip(str) ⇒ Object



229
230
231
# File 'lib/nandoc/data-source.rb', line 229

def dot_dot_strip str
  /\A\.\.(.*)\Z/ =~ str and $1
end

#dot_dot_strip_assert(str) ⇒ Object



232
233
234
235
# File 'lib/nandoc/data-source.rb', line 232

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



201
202
203
204
205
# File 'lib/nandoc/data-source.rb', line 201

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



206
207
208
# File 'lib/nandoc/data-source.rb', line 206

def identifier_bare_rootname identifier
  /\A\/([^\/]+)\// =~ identifier and $1
end

#identifier_bare_rootname_assert(identifier) ⇒ Object



209
210
211
212
# File 'lib/nandoc/data-source.rb', line 209

def identifier_bare_rootname_assert identifier
  identifier_bare_rootname(identifier) or
    fail("hack fail: couldn't find rootname for #{identifier.inspect}")
end

#parent_identifier(identifier) ⇒ Object



220
221
222
# File 'lib/nandoc/data-source.rb', line 220

def parent_identifier identifier
  identifier.sub(/[^\/]+\/$/, '')
end

#site_rootObject



223
224
225
# File 'lib/nandoc/data-source.rb', line 223

def site_root
  @site_root ||= @items.find{|x| x.identifier == '/' }
end

#slash_strip(identifier) ⇒ Object

exactly one leading and one trailing slash



214
215
216
# File 'lib/nandoc/data-source.rb', line 214

def slash_strip identifier
  /\A\/(.+)\/\Z/ =~ identifier and $1
end

#slash_strip_assert(identifier) ⇒ Object



217
218
219
# File 'lib/nandoc/data-source.rb', line 217

def slash_strip_assert identifier
  slash_strip(identifier) or fail("hack fail: #{identifier}")
end