Module: Kinbote::Util

Included in:
Attribute, Server, Site
Defined in:
lib/kinbote/util.rb

Instance Method Summary collapse

Instance Method Details

#dir_from_file(file) ⇒ Object



14
15
16
# File 'lib/kinbote/util.rb', line 14

def dir_from_file(file)
  file.split("/")[0...-1].join("/") + "/"
end

#file_without_extension(file) ⇒ Object



18
19
20
# File 'lib/kinbote/util.rb', line 18

def file_without_extension(file)
  file.split(".")[0...-1].join(".")
end

#output_path(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/kinbote/util.rb', line 30

def output_path(file)
  if type_from_file(file) == "haml"
    "#{$site.kinbote_path}/www/#{view_path(file)}".gsub(".haml", ".html")
  elsif type_from_file(file) == "sass"
    "#{$site.kinbote_path}/www/#{view_path(file)}".gsub("/sass/", "/css/").gsub(".sass", ".css")
  end
end


42
43
44
45
46
47
48
49
# File 'lib/kinbote/util.rb', line 42

def print_state
  @attributes.each do |a|
    puts "#{a.name} : #{a.pages.map{|p| p.slug}.join(',')}"
    a.values.each do |v|
      puts "  #{v.value} : #{v.pages.map{|p| p.slug}.join(',')}"
    end
  end
end

#slug_from_file(file) ⇒ Object



22
23
24
# File 'lib/kinbote/util.rb', line 22

def slug_from_file(file)
  file.split("/").last.split(".").first
end

#slugify(str) ⇒ Object



4
5
6
7
8
# File 'lib/kinbote/util.rb', line 4

def slugify(str)
  slug = str.downcase.gsub(/'/, '').gsub(/[^a-z0-9]+/, '-')
  slug = slug[0, slug.size - 1] if slug[-1, 1] == '-'
  slug
end

#sorted_attributes(attributes) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/kinbote/util.rb', line 51

def sorted_attributes(attributes)
  attributes.sort!{|x, y| x.name <=> y.name }
  attributes.each_with_index do |attribute, i|
    attributes.insert(0, attributes.delete_at(i)) if attribute.varname == "date"
  end
  attributes
end

#type_from_file(file) ⇒ Object



26
27
28
# File 'lib/kinbote/util.rb', line 26

def type_from_file(file)
  file.split(".").last
end

#varify(str) ⇒ Object



10
11
12
# File 'lib/kinbote/util.rb', line 10

def varify(str)
  slugify(str).gsub('-', '_')
end

#view_path(file) ⇒ Object



38
39
40
# File 'lib/kinbote/util.rb', line 38

def view_path(file)
  file[$site.kinbote_path.size + 7, file.size]
end