Module: EasyHtmlGenerator
- Defined in:
- lib/easy_html_generator.rb,
lib/easy_html_generator/version.rb
Overview
main module loads projects and dispatches rack requests
Defined Under Namespace
Modules: Generator
Classes: Checksum, Config, Generators, Project, ProjectPathResolver, RackDispatcher, Workspace
Constant Summary
collapse
- EHG_WORKSPACE_PATH =
File.expand_path File.join(File.dirname(__FILE__), '..')
- EHG_SRC_PATH =
File.join(EHG_WORKSPACE_PATH, 'src')
- EHG_SHARED_PATH =
File.join(EHG_SRC_PATH, 'shared')
- EHG_SHARED_HELPER_PATH =
File.join(EHG_SHARED_PATH, 'lib', 'helper')
- EHG_SHARED_GENERATORS_PATH =
File.join(EHG_SHARED_PATH, 'lib', 'generators')
- EHG_SHARED_STYLES_PATH =
File.join(EHG_SHARED_PATH, 'assets', 'styles')
- WORKSPACE_PATH =
Bundler.root
- SRC_PATH =
File.join(WORKSPACE_PATH, 'src')
- DIST_PATH =
File.join(WORKSPACE_PATH, 'dist')
- SHARED_PATH =
File.join(SRC_PATH, 'shared')
- SHARED_HELPER_PATH =
File.join(SHARED_PATH, 'lib', 'helper')
- SHARED_GENERATORS_PATH =
File.join(SHARED_PATH, 'lib', 'generators')
- SHARED_STYLES_PATH =
File.join(SHARED_PATH, 'assets', 'styles')
- CREATE_ON_INIT =
[
SRC_PATH,
DIST_PATH
]
- COPY_ON_INIT =
{
EHG_SHARED_PATH => SHARED_PATH,
"#{EHG_SRC_PATH}/template" => "#{SRC_PATH}/demo"
}
- VERSION =
'1.0.5'
Class Method Summary
collapse
Class Method Details
.clean_path(path) ⇒ Object
70
71
72
73
74
|
# File 'lib/easy_html_generator.rb', line 70
def self.clean_path(path)
path = path.slice(1..-1) if path.start_with? '/'
path.sub!("#{project_name_by_path(path)}/", '')
path
end
|
.dispatch(request) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/easy_html_generator.rb', line 49
def self.dispatch(request)
path = request.env['REQUEST_PATH'] || request.env['PATH_INFO']
cleaned_path = clean_path path
project_name = project_name_by_path path
project = Workspace.project_by_name project_name
return path unless project
project.generate if project.should_generate_for? cleaned_path
File.join(project.dist_path, cleaned_path)
end
|
.generate_all ⇒ Object
76
77
78
|
# File 'lib/easy_html_generator.rb', line 76
def self.generate_all
Workspace.projects.each { |_name, project| project.generate }
end
|
.generate_project(project) ⇒ Object
80
81
82
|
# File 'lib/easy_html_generator.rb', line 80
def self.generate_project(project)
Workspace.projects[project].generate
end
|
.project_name_by_path(path) ⇒ Object
64
65
66
67
68
|
# File 'lib/easy_html_generator.rb', line 64
def self.project_name_by_path(path)
path = path.slice(1..-1) if path.start_with? '/'
path = path.split('/').first if path.include? '/'
path
end
|
.projects ⇒ Object
45
46
47
|
# File 'lib/easy_html_generator.rb', line 45
def self.projects
Workspace.projects
end
|
.rack_app ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/easy_html_generator.rb', line 84
def self.rack_app
Rack::Builder.new do
use Rack::ShowExceptions
use EasyHtmlGenerator::RackDispatcher
use Rack::Deflater
use Rack::ContentLength
use Rack::StaticCache, urls: [''], root: EasyHtmlGenerator::DIST_PATH
use Rack::Static,
urls: [''],
root: EasyHtmlGenerator::DIST_PATH,
index: 'index.html'
run -> (_env) do
[404, { 'Content-Type' => 'text/plain' }, ['404 File not found!']]
end
end
end
|
.start_server(host, port) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/easy_html_generator.rb', line 102
def self.start_server(host, port)
config = { Host: host,
Port: port }
Thin::Logging.debug = true
Rack::Handler.get('thin').run(rack_app, config)
end
|