Module: Hechima

Defined in:
lib/hechima.rb,
lib/hechima/loader.rb,
lib/hechima/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.load(routing, hechima_root = "/app/views") ⇒ Object



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
# File 'lib/hechima/loader.rb', line 4

def self.load routing, hechima_root="/app/views"
  
  target_dir = File.join(Rails.root.to_s, hechima_root)
  anonymous_views = get_no_controller_views target_dir
  exclude_views = get_has_controller_views
  file_root = hechima_root.gsub(/\/app\/views/, "")

  (anonymous_views - exclude_views).each do |path|

    if path.split("/").count > 1
      path_array = path.split("/")
      path_array.delete(path_array.last) if %w(index).include? path_array.last
      route = path_array.join "/"

      routing.get "#{route}" => "hechima#index", :defaults => {:file => "#{file_root}/#{path}"}
    else
      routing.get "#{path}" => "hechima#index", :defaults => {:file => "#{file_root}/#{path}"}
    end

  end


  require "hechima/hechima_controller"

end