-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathapp.rb
153 lines (123 loc) · 4.03 KB
/
app.rb
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require 'rubygems'
require 'haml'
require 'yaml'
require 'mustache'
module Mulberry
module Framework
def self.version
'4.1.1'
end
def self.dojo_version
'1.6.0'
end
class Directories
def self.root
@root ||= File.expand_path(File.dirname(__FILE__))
end
def self.app
File.join(self.root, 'app')
end
def self.page_defs
File.join(self.root, 'base_apps', 'toura', 'page_defs')
end
def self.data_fixtures
File.join(self.app, 'data-fixtures')
end
def self.profiles
File.join(self.root, 'builder', 'profiles')
end
def self.build_root
File.join(self.app, 'tmp', 'build')
end
def self.js_builds
File.join(self.root, 'js_builds')
end
def self.dojo
File.join(self.app, "dojo-release-#{Mulberry::Framework.dojo_version}-src")
end
def self.project_templates
File.join(self.root, 'builder', 'project_templates')
end
def self.cli
File.join(self.root, 'cli')
end
def self.templates
File.join(self.cli, 'templates')
end
end
class Templates
def self.root
@root ||= File.join(Mulberry::Framework::Directories.root, 'cli', 'templates', 'app')
end
def self.index_html
File.join(self.root, 'index.html.haml')
end
def self.config
File.join(self.root, 'AppConfig.js.mustache')
end
end
class Generators
def self.page_defs(page_defs)
str = ''
page_defs.each do |page_def_name, config|
str << "mulberry.pageDef('#{page_def_name}', #{JSON.pretty_generate(config)});\n\n"
end
str
end
def self.index_html(params = {})
obj = Object.new
tmpl = File.read(Mulberry::Framework::Templates.index_html)
haml = Haml::Engine.new(tmpl, :attr_wrapper => '"')
haml.def_method(obj, :render, *params.keys)
obj.render(params)
end
def self.config(os, device_type, binding = {})
tmpl = File.read(Mulberry::Framework::Templates.config)
defaults = {
'id' => 12345,
'build_date' => Time.now.to_i.to_s,
'force_streaming' => false,
'force_local' => false,
'skip_version_check' => false,
'app_version' => Mulberry::Framework::version,
'debug' => false,
'force_local' => false,
'postscript' => '',
'locale' => 'en-us',
'ads' => false,
'sibling_nav' => true,
'sharing' => true,
'favorites' => true,
'font_size' => true,
'multi_line_child_nodes' => false,
'debug_page' => true,
'environment' => 'production'
}
settings = defaults.merge(binding)
base_config = {
'id' => settings['id'],
'locale' => settings['locale'],
'buildDate' => settings['build_date'],
'appVersion' => settings['app_version'],
'updateUrl' => settings['update_url'],
'versionUrl' => settings['version_url'],
}
unless os.nil? or device_type.nil?
# only set device config if values were provided
base_config['device'] = {
'type' => device_type,
'os' => os
}
end
settings['base_config'] = JSON.pretty_generate(base_config)
Mustache.render(tmpl, settings)
end
def self.data(data_object)
"toura.data.local = #{JSON.pretty_generate(data_object)};"
end
end
end
end
# Setup load paths
$: << Mulberry::Framework::Directories.root
$: << File.join(Mulberry::Framework::Directories.root, 'lib')