Module: Pageify

Defined in:
lib/pageify.rb

Instance Method Summary collapse

Instance Method Details

#createElement(raw_row) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pageify.rb', line 13

def createElement(raw_row)
  element = PageObject.create(raw_row)
  define_method(element.name) do |*arguments|
    unless arguments.eql? []
      $global_selector = (element.self_selector % arguments).strip_quotes.strip
    else
      $global_selector = (element.self_selector % '').strip_quotes.strip
    end
    element
  end
  element
end

#get_procesed(file) ⇒ Object



44
45
46
47
48
# File 'lib/pageify.rb', line 44

def get_procesed (file)
  rawArray= IO.read(file).split("\n").map{|x| x.rstrip}
  rawArray -= [""]
  rawArray = replace_sections(rawArray,file)
end

#pageify(base_dir) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/pageify.rb', line 5

def pageify(base_dir)
  base_dir.chomp! '/'
  all_pages = []
  (Dir["#{base_dir}/**/*.yml"]-Dir["#{base_dir}/**/_*.yml"]).each do |file|
    to_page_objects file
  end
end

#replace_sections(parent_array, file) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pageify.rb', line 26

def replace_sections (parent_array,file)
  processed_parent = []
  parent_array.each do |row|
    if row.lstrip.start_with?":"
      section_file = "#{File.dirname (file)}/#{row.split(':')[1]}.yml"
      section_file = "#{File.dirname(section_file)}/_#{File.basename(section_file)}"
      section_array =  get_procesed(section_file)
      section_array.each_with_index do |value,index|
        section_array[index] = " " * row.lspace + value
      end
      processed_parent =  processed_parent + section_array
    else
      processed_parent =  processed_parent + [row]
    end
  end
  processed_parent
end

#to_page_objects(file) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pageify.rb', line 50

def to_page_objects(file)
  rawArray = get_procesed(file)
  parentElement = rawArray.shift
  page = createElement(parentElement)
  parent = [page]
  until rawArray.empty? do
    thisElement = rawArray.first
    nextElement = rawArray[1]
    until parent.last.intend < thisElement.lspace do
      parent.pop
    end
    element = parent.last.createChild(thisElement)
    rawArray.shift
    parent << element if rawArray.any? &&thisElement.lspace < nextElement.lspace
  end
end