adaptrex 0.9.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,222 @@
1
+ #
2
+ # Copyright 2012 Adaptrex, LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ #
18
+ # Class to generate Ext applications (pages) in a way that is
19
+ # Adaptrex friendly including the Adaptrex packaging process
20
+ #
21
+
22
+ require "etc"
23
+ require "pathname"
24
+ require "fileutils"
25
+ require "erb"
26
+ require "adaptrex/sdkinstaller"
27
+ require "adaptrex/themeinstaller"
28
+
29
+ class AdaptrexGenerator
30
+ def initialize(adaptrexConfig, appConfig, basePath)
31
+ @appConfig = appConfig
32
+ @adaptrexConfig = adaptrexConfig
33
+ @basePath = basePath
34
+
35
+ # Launch our Application Wizard
36
+ appWizard
37
+ end
38
+
39
+ def appWizard
40
+ #
41
+ # Get the application type
42
+ #
43
+ puts "Application (Page) Type".blue
44
+ puts " [1] ExtJS"
45
+ puts " [2] Sencha Touch"
46
+ sdkType = promptSDKType
47
+ puts ""
48
+ @appConfig.lastSDK = sdkType
49
+ @appConfig.write
50
+
51
+
52
+ #
53
+ # Get the sdk version for this sdk type
54
+ #
55
+ sdkVersion = nil
56
+ if sdkType == "ext"
57
+ sdkVersion = @appConfig.extVersion
58
+ sdkName = "ExtJS"
59
+ else
60
+ sdkVersion = @appConfig.touchVersion
61
+ sdkName = "Sencha Touch"
62
+ end
63
+
64
+ #
65
+ # Make sure we've got the sdk version configured
66
+ #
67
+ if sdkVersion.nil?
68
+ sdkInstaller = SDKInstaller.new(@adaptrexConfig, @appConfig, sdkType)
69
+ puts ""
70
+ if not sdkInstaller.success then return end
71
+
72
+ #
73
+ # If we don't have a theme for this webapp and sdk... install one
74
+ #
75
+ themeInstaller = ThemeInstaller.new(@adaptrexConfig, @appConfig, sdkType)
76
+ puts ""
77
+ if not themeInstaller.success then return end
78
+ end
79
+
80
+ #
81
+ # Ask the user for the name of the app (page)
82
+ #
83
+ puts((sdkName + " Application (Page) Name").blue)
84
+ appName = promptForPageName
85
+
86
+ #
87
+ # Ask the user for the path to this app (page)
88
+ #
89
+ puts(("Path For " + appName).blue)
90
+ appPath = promptForPagePath
91
+
92
+ #
93
+ # Make sure this page doesn't already exist
94
+ #
95
+ if File.directory?appPath
96
+ puts "App (page) already exists at this path (" + appPath + ")".err
97
+ return appWizard
98
+ end
99
+
100
+ #
101
+ # Let the user know what we're doing?
102
+ #
103
+ puts "Generating your app (page)..."
104
+
105
+ #
106
+ # Copy the folder template
107
+ #
108
+ templateFolder = @basePath + "/templates/" + sdkType
109
+ FileUtils.mkdir_p(appPath)
110
+ FileUtils.cp_r(Dir[templateFolder + "/*"], appPath)
111
+
112
+ templateSettings = TemplateSettings.new
113
+ templateSettings.appName = appName
114
+
115
+ applyTemplate(appPath + "/app.js", templateSettings)
116
+ applyTemplate(appPath + "/app/view/Main.js", templateSettings)
117
+
118
+ # Process Additional Ext Templates
119
+ if sdkType == "ext"
120
+ applyTemplate(appPath + "/app/view/Viewport.js", templateSettings)
121
+ applyTemplate(appPath + "/app/controller/Main.js", templateSettings)
122
+ end
123
+
124
+ # Success!
125
+ puts((appName + " (" + appPath + ") Generated\n\n").success)
126
+ @appConfig.pages[appPath] = appName + "," + sdkType
127
+ @appConfig.write
128
+
129
+ # Ask the user if they want to create another page
130
+ print "Do you want to create another page? [n]: "
131
+ doAnother = STDIN.gets.chomp.downcase
132
+ if (doAnother == "y" or doAnother == "yes")
133
+ puts ""
134
+ return appWizard
135
+ end
136
+ end
137
+
138
+
139
+ def promptForPageName
140
+ print "Enter the name of the new app (page): "
141
+ response = STDIN.gets.chomp
142
+
143
+ if response == ""
144
+ puts "You must enter an app (page) name".err
145
+ return promptForPageName
146
+ end
147
+
148
+ if not response.validate?(/\A[A-Z][a-zA-Z0-9]*\z/)
149
+ puts "Must begin with a capital letter and contain only letters and numbers".err
150
+ return promptForPageName
151
+ end
152
+
153
+ return response
154
+ end
155
+
156
+
157
+ #
158
+ # Prompt for the path to use for this page
159
+ #
160
+ def promptForPagePath
161
+ print "Enter the path for this new app (page): "
162
+ response = STDIN.gets.chomp
163
+
164
+ if response == ""
165
+ puts "You must enter an app (page) name".err
166
+ return promptForPagePath
167
+ end
168
+
169
+ responseFolder = response + "/"
170
+ if (responseFolder.start_with?"ext/" or response.start_with?"touch/" or response.start_with?"adaptrex/")
171
+ puts "'" + responseFolder.split("/")[0] + "' is a reserved folder name".err
172
+ return promptForPagePath
173
+ end
174
+
175
+ if not response.validate?(/\A[a-z][a-z0-9\/\-\_]*\z/)
176
+ puts "Must be lowercase letters, numbers, underscore (_) or dash (-)".err
177
+ return promptForPagePath
178
+ end
179
+
180
+ if not @appConfig.pages[response].nil?
181
+ puts "An app (page) already exists at that path".err
182
+ return promptForPagePath
183
+ end
184
+
185
+
186
+ return response
187
+ end
188
+
189
+
190
+ #
191
+ # Prompt for the SDK Type To use for this page
192
+ #
193
+ def promptSDKType
194
+ default = "1"
195
+ if not @appConfig.lastSDK.nil?
196
+ if @appConfig.lastSDK == "ext" then default = "1" else default = "2" end
197
+ end
198
+
199
+ print "Which type of page do you want to create? [" + default + "] : "
200
+ response = STDIN.gets.chomp
201
+ if response == "" then return default end
202
+ if response == "1" then return "ext" end
203
+ if response == "2" then return "touch" end
204
+
205
+ puts "Invalid selection. Enter a number from 1 to 2".err
206
+ return promptSDKType
207
+ end
208
+
209
+ def applyTemplate(filePath, templateSettings)
210
+ template = File.open(filePath, "r").read
211
+ output = ERB.new(template).result(templateSettings.get_binding)
212
+ File.open(filePath, "w") do |file| file.puts output end
213
+ end
214
+
215
+ end
216
+
217
+ class TemplateSettings
218
+ attr_accessor :appName, :sdkFolder
219
+ def get_binding
220
+ binding
221
+ end
222
+ end
@@ -0,0 +1,102 @@
1
+ require "adaptrex/bootstrapinstaller"
2
+ require "adaptrex/themeinstaller"
3
+
4
+ class SDKInstaller
5
+
6
+ attr_accessor :success
7
+ def initialize(adaptrexConfig, appConfig, sdkType)
8
+ self.success = false
9
+ isExt = sdkType == "ext"
10
+ if sdkType == "ext" then sdkName = "ExtJS" else sdkName = "Sencha Touch" end
11
+ puts((sdkName + " SDK Installer").blue)
12
+
13
+ @sdkVersions = nil
14
+ if isExt
15
+ @sdkVersions = adaptrexConfig.extVersions
16
+ else
17
+ @sdkVersions = adaptrexConfig.touchVersions
18
+ end
19
+
20
+ if @sdkVersions.length == 0
21
+ #
22
+ # If we don't have any SDKs for this type, warn and return
23
+ #
24
+ puts "You don't have any " + sdkName + " SDKs available. Either add".err
25
+ puts "the correct SDK folder or create a different type of app (page).\n\n"
26
+ return
27
+ end
28
+
29
+ if @sdkVersions.length > 1
30
+ #
31
+ # If we have more than one SDK for this type, ask the user for the right one
32
+ #
33
+ index = 1
34
+ @sdkVersions.each{|version|
35
+ puts " [" + index.to_s + "] " + version
36
+ index += 1
37
+ }
38
+ sdkVersion = promptForSDKVersion
39
+
40
+ else
41
+ #
42
+ # If we only have one SDK for this type, configure that one
43
+ #
44
+ sdkVersion = @sdkVersions[0]
45
+ end
46
+
47
+ #
48
+ # Update the AppConfig with the selected SDK Version
49
+ #
50
+ if isExt then appConfig.extVersion = sdkVersion else appConfig.touchVersion = sdkVersion end
51
+
52
+ #
53
+ # Add the SDK folder to our adaptrex folder
54
+ #
55
+ FileUtils.mkdir_p("adaptrex/" + sdkType)
56
+
57
+ #
58
+ # Copy ext.js
59
+ #
60
+ sdkFolder = adaptrexConfig.weblibPath + "/" + sdkVersion
61
+ if isExt
62
+ FileUtils.cp(sdkFolder + "/ext.js", "adaptrex/ext/ext.js")
63
+ else
64
+ FileUtils.cp(sdkFolder + "/sencha-touch.js", "adaptrex/touch/sencha-touch.js")
65
+ end
66
+
67
+ #
68
+ # Build the bootstrap file for this Adaptrex/Ext/Sencha combination
69
+ #
70
+ bootstrapInstaller = BootstrapInstaller.new(adaptrexConfig, appConfig, sdkType)
71
+ if not bootstrapInstaller.success then return end
72
+
73
+
74
+ # Update appConfig if out sdk installation is successful
75
+ appConfig.write
76
+
77
+ # Success!
78
+ puts((sdkName + "Configured (" + sdkVersion + ")").success)
79
+ self.success = true
80
+ end
81
+
82
+
83
+ def promptForSDKVersion
84
+ print "Select the version to use for this webapp: "
85
+ selection = STDIN.gets.chomp
86
+
87
+ len = @sdkVersions.length
88
+ erm = ("Invalid Selection. Enter a number from 1 to " + len.to_s).err
89
+ if not selection.numeric?
90
+ puts erm
91
+ return promptForSDKVersion
92
+ end
93
+
94
+ selection = Integer(selection)
95
+ if not selection === 1..len
96
+ puts erm
97
+ return promptForSDKVersion
98
+ end
99
+
100
+ return @sdkVersions[selection - 1]
101
+ end
102
+ end
@@ -0,0 +1,118 @@
1
+ require "fileutils"
2
+
3
+ class ThemeInstaller
4
+
5
+ @@touchThemes = [
6
+ #["Adaptrex Touch Theme", "adaptrex", "adaptrex-all.css"],
7
+ ["Sencha Touch Default Theme", "default", "ext-all.css"],
8
+ #["Custom Theme", "custom", "custom"]
9
+ ]
10
+
11
+ @@extThemes = [
12
+ #["Adaptrex Touch Theme", "adaptrex", "adaptrex-all.css"],
13
+ ["ExtJS Default Theme", "default", "ext-all.css"],
14
+ ["ExtJS Gray Theme", "gray", "ext-all-gray.css"],
15
+ ["ExtJS Access Theme", "access", "ext-all-access.css"],
16
+ ["ExtJS Neptune Theme", "neptune", "ext-neptune.css"],
17
+ #["Custom Theme", "custom", "custom"],
18
+ ]
19
+
20
+ attr_accessor :success
21
+ def initialize(adaptrexConfig, appConfig, sdkType)
22
+ self.success = false
23
+ isExt = sdkType == "ext"
24
+ if sdkType == "ext" then sdkName = "ExtJS" else sdkName = "Sencha Touch" end
25
+ puts((sdkName + " Theme Installer").blue)
26
+ if sdkType == "touch" then options = @@touchThemes else options = @@extThemes end
27
+
28
+ if options.length == 1
29
+ theme = options[0]
30
+ else
31
+ index = 0
32
+ options.each {|option|
33
+ puts " [" + (index + 1).to_s + "] " + options[index][0]
34
+ index += 1
35
+ }
36
+ theme = promptForTheme(sdkType)
37
+ end
38
+ puts "Installing " + theme[0] + "..."
39
+
40
+ imgFolder = theme[1]
41
+ cssFile = theme[2]
42
+
43
+ # Start processing the theme
44
+ targetFolder = "adaptrex/" + sdkType + "/resources"
45
+
46
+ # Clean out old theme
47
+ FileUtils.rm_rf(targetFolder)
48
+ FileUtils.mkdir_p(targetFolder + "/css")
49
+
50
+ # Add additional touch theme files
51
+ if sdkType == "touch"
52
+ sdkResourcesFolder = adaptrexConfig.weblibPath + "/" + appConfig.touchVersion + "/resources"
53
+ Dir.glob(sdkResourcesFolder + "/css/*") {|f|
54
+ if not File.directory?f
55
+ FileUtils.cp(File.expand_path(f), targetFolder + "/css/")
56
+ end
57
+ }
58
+
59
+ # Add additional ext theme files
60
+ else
61
+ FileUtils.mkdir_p(targetFolder + "/themes/images")
62
+
63
+ # Adaptrex Theme Not Yet Implemented
64
+ if imgFolder == "adaptrex"
65
+ sdkResourcesFolder = adaptrexConfig.weblibPath + "/" + appConfig.adaptrexVersion + "/resources"
66
+ FileUtils.cp(sdkResourcesFolder + "/css/" + cssFile, targetFolder + "/css/" + cssFile)
67
+ FileUtils.cp_r(sdkResourcesFolder + "/themes/images/" + imgFolder, targetFolder + "/themes/images/" + imgFolder)
68
+
69
+ # Custom Themes Not Yet Implemented
70
+ elsif imgFolder == "custom"
71
+
72
+
73
+ # Standard Ext Themes
74
+ else
75
+ sdkResourcesFolder = adaptrexConfig.weblibPath + "/" + appConfig.extVersion + "/resources"
76
+ FileUtils.cp(sdkResourcesFolder + "/css/" + cssFile, targetFolder + "/css/" + cssFile)
77
+ FileUtils.cp_r(sdkResourcesFolder + "/themes/images/" + imgFolder, targetFolder + "/themes/images/" + imgFolder)
78
+
79
+ # Neptune needs some extra files
80
+ if imgFolder == "neptune"
81
+ FileUtils.cp_r(sdkResourcesFolder + "/themes/images/default", targetFolder + "/themes/images/default/")
82
+ FileUtils.cp(adaptrexConfig.weblibPath + "/" + appConfig.extVersion + "/ext-neptune.js", "adaptrex/" + sdkType + "/ext-neptune.js")
83
+ end
84
+ end
85
+ end
86
+
87
+ # Success!
88
+ puts((theme[0] + " Configured").success)
89
+ self.success = true
90
+ end
91
+
92
+ def promptForTheme(sdkType)
93
+ # Temporary until we add support for other touch themes
94
+ if sdkType == "touch"
95
+ return @@touchThemes[0]
96
+ end
97
+
98
+ print "Which theme do you want to use? [1]: "
99
+
100
+ if sdkType == "touch" then options = @@touchThemes else options = @@extThemes end
101
+
102
+ selection = STDIN.gets.chomp
103
+ if selection == "" then selection = "1" end
104
+
105
+ len = options.length
106
+ erm = ("Invalid selection. Enter a number from 1 to " + len.to_s).err
107
+ if not selection.numeric?
108
+ puts erm
109
+ return promptForTheme(sdkType)
110
+ end
111
+ selection = Integer(selection)
112
+ if not selection === 1..len
113
+ puts erm
114
+ return promptForTheme(sdkType)
115
+ end
116
+ return options[selection - 1]
117
+ end
118
+ end
@@ -0,0 +1,44 @@
1
+ require "adaptrex/themeinstaller"
2
+
3
+ class ThemeTool
4
+
5
+ def initialize(adaptrexConfig, appConfig)
6
+ @appConfig = appConfig
7
+ ext = appConfig.extVersion
8
+ touch = appConfig.touchVersion
9
+
10
+ if not ext.nil? and not touch.nil?
11
+ puts "Theme SDK".blue
12
+ puts " [1] ExtJS"
13
+ puts " [2] Sencha Touch"
14
+ sdkType = promptSDKType
15
+ elsif not ext.nil?
16
+ sdkType = "ext"
17
+ elsif not touch.nil?
18
+ typeType = "touch"
19
+ else
20
+ puts "Your webapp does not have any configured SDKs. When you create a new".warn
21
+ puts "page using 'adaptrex generate', your SDK and theme will be configured.".indent
22
+ return
23
+ end
24
+ puts ""
25
+
26
+ themeInstaller = ThemeInstaller.new(adaptrexConfig, appConfig, sdkType)
27
+ end
28
+
29
+ def promptSDKType
30
+ default = "1"
31
+ if not @appConfig.lastSDK.nil?
32
+ if @appConfig.lastSDK == "ext" then default = "1" else default = "2" end
33
+ end
34
+
35
+ print "Which SDK do you want to update the theme for? [" + default + "] : "
36
+ response = STDIN.gets.chomp
37
+ if response == "" then return default end
38
+ if response == "1" then return "ext" end
39
+ if response == "2" then return "touch" end
40
+
41
+ puts "Invalid selection. Enter a number from 1 to 2".err
42
+ return promptSDKType
43
+ end
44
+ end
@@ -0,0 +1,64 @@
1
+ require "adaptrex/sdkinstaller"
2
+ require "adaptrex/adaptrexinstaller"
3
+
4
+ class UpgradeTool
5
+
6
+ def initialize(adaptrexConfig, appConfig)
7
+ ext = appConfig.extVersion
8
+ touch = appConfig.touchVersion
9
+
10
+ puts "Upgrade SDK".blue
11
+ @sdks = [["Adaptrex", "adaptrex"]]
12
+ if not ext.nil? then @sdks.push(["ExtJS", "ext"]) end
13
+ if not touch.nil? then @sdks.push(["Sencha Touch", "touch"]) end
14
+ i = 0
15
+
16
+ if @sdks.length == 1
17
+ sdkType = @sdks[0][1]
18
+ else
19
+ for sdk in @sdks
20
+ puts " [" + (i + 1).to_s + "] " + @sdks[i][0]
21
+ i += 1
22
+ end
23
+ sdkType = promptSDKType[1]
24
+ puts ""
25
+ end
26
+
27
+ if sdkType == "adaptrex"
28
+ adaptrexInstaller = AdaptrexInstaller.new(adaptrexConfig)
29
+ appConfig.adaptrexVersion = adaptrexInstaller.version
30
+ appConfig.write
31
+
32
+ if not appConfig.extVersion.nil?
33
+ BootstrapInstaller.new(adaptrexConfig, appConfig, "ext")
34
+ end
35
+ if not appConfig.touchVersion.nil?
36
+ BootstrapInstaller.new(adaptrexConfig, appConfig, "touch")
37
+ end
38
+
39
+ else
40
+ sdkInstaller = SDKInstaller.new(adaptrexConfig, appConfig, sdkType)
41
+ end
42
+ end
43
+
44
+ def promptSDKType
45
+ print "Which SDK do you want to upgrade? : "
46
+ selection = STDIN.gets.chomp
47
+
48
+ len = @sdks.length
49
+ erm = ("Invalid selection. Enter a number from 1 to " + len.to_s).err
50
+ if not selection.numeric?
51
+ puts erm
52
+ return promptSDKType
53
+ end
54
+
55
+ selection = Integer(selection)
56
+ if not selection === 1..len
57
+ puts erm
58
+ return promptSDKType
59
+ end
60
+
61
+ return @sdks[selection - 1]
62
+ end
63
+
64
+ end