Class: Textigniter::List

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

Overview

lists files

Instance Method Summary collapse

Constructor Details

#initializeList

Returns a new instance of List.



4
5
6
# File 'lib/textigniter/list.rb', line 4

def initialize
  
end

Instance Method Details

#get_build_list(format) ⇒ Object

generates a build list



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/textigniter/list.rb', line 14

def get_build_list(format)
  # Create the html list
  build_list1 = Dir.glob("#{$twd}/#{format}/**/*")
  # build the manifest
  manifest_build_list = manifest.get_manifest("#{format}")
  # create an array to store the new build list in
  build_list2 = Array.new
  # Clean up the build list
  build_list1.each do |l|
    # if not a directory keep the file
    unless File.directory?(l)
      build_list2.push({ filename: l, modified_at: File.mtime(l) })
    end
  end      
  # create the cleaned list
  cleaned_build_list = build_list2 - manifest_build_list

  unless cleaned_build_list.count == 0
    # perfect_build_list
    perfect_build_list = Array.new
    # do some final pruning
    cleaned_build_list.each do |item|
      perfect_build_list.push item[:filename]
    end
    # Return the list
    return perfect_build_list
  else
    return nil
  end
end

#get_directory_listing(format = nil) ⇒ Object

print requested list to the command line



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/textigniter/list.rb', line 46

def get_directory_listing(format=nil)
  # get the keyword for message output
  unless format.nil?
    keyword = format
  else
    keyword = "everything"
  end    
  # output message
  STDOUT.puts "Building a directory listing for ".yellow_on_black + "[#{keyword}]".blue_on_black
  # files hash
  files = Hash.new
  # check for format
  unless format.nil?
    files[format] = Dir.glob("#{$twd}/#{format}/**/*")
  # get everything if format not specified
  else
    files['content'] = Dir.glob("#{$twd}/content/**/*")
    files['layouts'] = Dir.glob("#{$twd}/layouts/**/*")
    files['styles'] = Dir.glob("#{$twd}/styles/**/*")
    files['scripts'] = Dir.glob("#{$twd}/scripts/**/*")
  end
  # return files
  return files
end

#manifestObject

manifest parser



9
10
11
# File 'lib/textigniter/list.rb', line 9

def manifest
  @manifest = Textigniter::Parsers::ManifestParser.new
end


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/textigniter/list.rb', line 71

def print_directory_listing(files)
  # break files apart by key, value
  files.each do |key, values|
    # print the containing directory
    STDOUT.puts ".textigniter/#{key}".blue_on_black
    # print the files
    values.each do |file|
      unless File.directory?(file)
        STDOUT.puts "--#{file.gsub("#{$twd}/#{key}/", '')}".yellow_on_black
      end
    end
  end
end