Class: Cb

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

Class Method Summary collapse

Class Method Details

.partial_helper(file_name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/view_tree.rb', line 28

def self.partial_helper(file_name)
  # find partials in the file 
  # print out the partial name and
  # push all the partials into queue

  reg_partial_name = /(?<=(partial=>)|(render)|(spotpartial=>))\s*['"][a-zA-Z_\/-]+(?=['"])/
    
  begin 
    File.readlines(file_name).each do |line|
      if !reg_partial_name.match(line).nil?
        partial_name = reg_partial_name.match(line)
        partial_name = partial_name.to_s.gsub!(/[\s'"]*/, "")
        if !partial_name[/spot_loader/].nil?
          partial_name = line[/(?<=spotpartial=>)\s*['"][a-zA-Z_\/-]+(?=['"])/].to_s.gsub!(/[\s'"]*/, "")
        else
          partial_name = File.basename(partial_name)
        end
        self.view_helper("_" + partial_name + ".html.erb" )
      end
    end
  rescue
    puts "Please input correct controller and action name."
    exit
  end
end

.rel(controller_action_name) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/view_tree.rb', line 55

def self.rel(controller_action_name)

  # Check that if user has input "bundle install --path vendor"

  if controller_action_name.size == 0 || controller_action_name[0] == "#" ||
    controller_action_name[controller_action_name.size - 1] == "#" || controller_action_name.include?("*") ||
    !controller_action_name.include?("#")
    puts "Please input controller and action name."
    exit
  end

  bundle_installed = false

  Dir.open("./vendor").each do |dirname|
    bundle_installed = true if dirname == "ruby"
  end

  if !bundle_installed 
    puts "Please use bundle install --path vendor instead of bundle install"
    exit 
  end

  # Scan the gem list array, find all the views used

  view_name = controller_action_name.gsub(/#/, "/")

  

  self.view_helper(view_name)

  if $file_queue.size == 0
    puts ""
    puts "Please check the controller and action name, I can't find that page."
    exit 
  end

  $file_queue.push(["#{$niche_intl}/app/views/layouts/cb_intl/application.html.erb"])

  # Print out all the rendered partial

  while $file_queue.size != 0
    file_name = $file_queue.pop() 
    puts file_name
    if file_name.class == Array
      file_name = file_name.first
    end
    if file_name !~ /featured_employers/
      self.partial_helper(file_name)
    end
  end
end

.view_helper(view_name) ⇒ Object

Define methods partial helper and view helper



16
17
18
19
20
21
22
23
24
25
# File 'lib/view_tree.rb', line 16

def self.view_helper(view_name)
  $gem_list.each do |gem|
    if Dir["#{gem}/**/#{view_name}*"].size != 0
      Dir["#{gem}/**/#{view_name}*"].each do |file|
        $file_queue.push(file)
      end
      break
    end
  end
end