Class: Textigniter::Plugins::Slug

Inherits:
Object
  • Object
show all
Defined in:
lib/textigniter/plugins/slug.rb

Instance Method Summary collapse

Instance Method Details

#parse(h) ⇒ Object



3
4
5
6
7
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
# File 'lib/textigniter/plugins/slug.rb', line 3

def parse(h)
  # get the value
  value = h['slug']
  # split the value by /
  values = value.split(/\//)
  # get the filename
  filename = values.last
  # values pop
  values.pop

  # check for date in slug
  valid = Date.parse(filename[0..9]) rescue false
  
  # slug does contain date
  if valid != false
    slug = "#{values.join('/')}/#{filename.gsub(filename[0..9] + "-", '')}"      
  # slug does not contain date
  else
    slug = value
  end
  
  # check for path name
  slug = "#{$owd}/#{slug}" unless slug.include? $twd

  # check for index
  slug = slug.sub('index', '')
  
  # replace twd with owd
  slug = slug.sub("#{$twd}/content", "#{$owd}")
  
  # return parsed slug
  return slug
      
end