Class: Volt::App

Inherits:
Object show all
Defined in:
lib/volt/volt/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_path) ⇒ App

Returns a new instance of App.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/volt/volt/app.rb', line 5

def initialize(app_path)
  # Setup root path
  Volt.root = app_path

  # Run the app config to load all users config files
  unless RUBY_PLATFORM == 'opal'
    if Volt.server?
      @page = Page.new

      # Setup a global for now
      $page = @page unless defined?($page)
    end
  end

  # Require in app and initializers
  unless RUBY_PLATFORM == 'opal'
    Volt.run_app_and_initializers
  end

  # Load component paths
  @component_paths = ComponentPaths.new(app_path)
  @component_paths.require_in_components(@page || $page)

  unless RUBY_PLATFORM == 'opal'
    setup_router
    require_http_controllers
  end
end

Instance Attribute Details

#component_pathsObject (readonly)

Returns the value of attribute component_paths.



3
4
5
# File 'lib/volt/volt/app.rb', line 3

def component_paths
  @component_paths
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/volt/volt/app.rb', line 3

def page
  @page
end

#routerObject (readonly)

Returns the value of attribute router.



3
4
5
# File 'lib/volt/volt/app.rb', line 3

def router
  @router
end

Instance Method Details

#require_http_controllersObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/volt/volt/app.rb', line 44

def require_http_controllers
  @component_paths.app_folders do |app_folder|
    # Sort so we get consistent load order across platforms
    Dir["#{app_folder}/*/controllers/server/*.rb"].each do |ruby_file|
      #path = ruby_file.gsub(/^#{app_folder}\//, '')[0..-4]
      #require(path)
      require(ruby_file)
    end
  end
end

#setup_routerObject



35
36
37
38
39
40
41
42
# File 'lib/volt/volt/app.rb', line 35

def setup_router
  # Find the route file
  home_path  = @component_paths.component_paths('main').first
  routes = File.read("#{home_path}/config/routes.rb")
  @router = Routes.new.define do
    eval(routes)
  end
end