Class: AdaptrexGenerator
- Inherits:
-
Object
- Object
- AdaptrexGenerator
- Defined in:
- lib/adaptrex/generate.rb
Instance Method Summary collapse
- #applyTemplate(filePath, templateSettings) ⇒ Object
- #appWizard ⇒ Object
-
#initialize(adaptrexConfig, appConfig, basePath) ⇒ AdaptrexGenerator
constructor
A new instance of AdaptrexGenerator.
- #promptForPageName ⇒ Object
-
#promptForPagePath ⇒ Object
Prompt for the path to use for this page.
-
#promptSDKType ⇒ Object
Prompt for the SDK Type To use for this page.
Constructor Details
#initialize(adaptrexConfig, appConfig, basePath) ⇒ AdaptrexGenerator
30 31 32 33 34 35 36 37 |
# File 'lib/adaptrex/generate.rb', line 30 def initialize(adaptrexConfig, appConfig, basePath) @appConfig = appConfig @adaptrexConfig = adaptrexConfig @basePath = basePath # Launch our Application Wizard appWizard end |
Instance Method Details
#applyTemplate(filePath, templateSettings) ⇒ Object
209 210 211 212 213 |
# File 'lib/adaptrex/generate.rb', line 209 def applyTemplate(filePath, templateSettings) template = File.open(filePath, "r").read output = ERB.new(template).result(templateSettings.get_binding) File.open(filePath, "w") do |file| file.puts output end end |
#appWizard ⇒ Object
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 |
# File 'lib/adaptrex/generate.rb', line 39 def appWizard # # Get the application type # puts "Application (Page) Type".blue puts " [1] ExtJS" puts " [2] Sencha Touch" sdkType = promptSDKType puts "" @appConfig.lastSDK = sdkType @appConfig.write # # Get the sdk version for this sdk type # sdkVersion = nil if sdkType == "ext" sdkVersion = @appConfig.extVersion sdkName = "ExtJS" else sdkVersion = @appConfig.touchVersion sdkName = "Sencha Touch" end # # Make sure we've got the sdk version configured # if sdkVersion.nil? sdkInstaller = SDKInstaller.new(@adaptrexConfig, @appConfig, sdkType) puts "" if not sdkInstaller.success then return end # # If we don't have a theme for this webapp and sdk... install one # themeInstaller = ThemeInstaller.new(@adaptrexConfig, @appConfig, sdkType) puts "" if not themeInstaller.success then return end end # # Ask the user for the name of the app (page) # puts((sdkName + " Application (Page) Name").blue) appName = promptForPageName # # Ask the user for the path to this app (page) # puts(("Path For " + appName).blue) appPath = promptForPagePath # # Make sure this page doesn't already exist # if File.directory?appPath puts(("App (page) already exists at this path (" + appPath + ")").err) return appWizard end # # Let the user know what we're doing? # puts "Generating your app (page)..." # # Copy the folder template # templateFolder = @basePath + "/templates/" + sdkType FileUtils.mkdir_p(appPath) FileUtils.cp_r(Dir[templateFolder + "/*"], appPath) templateSettings = TemplateSettings.new templateSettings.appName = appName applyTemplate(appPath + "/app.js", templateSettings) applyTemplate(appPath + "/app/view/Main.js", templateSettings) # Process Additional Ext Templates if sdkType == "ext" applyTemplate(appPath + "/app/view/Viewport.js", templateSettings) applyTemplate(appPath + "/app/controller/Main.js", templateSettings) end # Success! puts((appName + " (" + appPath + ") Generated\n\n").success) @appConfig.pages[appPath] = appName + "," + sdkType @appConfig.write # Ask the user if they want to create another page print "Do you want to create another page? [n]: " doAnother = STDIN.gets.chomp.downcase if (doAnother == "y" or doAnother == "yes") puts "" return appWizard end end |
#promptForPageName ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/adaptrex/generate.rb', line 139 def promptForPageName print "Enter the name of the new app (page): " response = STDIN.gets.chomp if response == "" puts "You must enter an app (page) name".err return promptForPageName end if not response.validate?(/\A[A-Z][a-zA-Z0-9]*\z/) puts "Must begin with a capital letter and contain only letters and numbers".err return promptForPageName end return response end |
#promptForPagePath ⇒ Object
Prompt for the path to use for this page
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/adaptrex/generate.rb', line 160 def promptForPagePath print "Enter the path for this new app (page): " response = STDIN.gets.chomp if response == "" puts "You must enter an app (page) name".err return promptForPagePath end responseFolder = response + "/" if (responseFolder.start_with?"ext/" or response.start_with?"touch/" or response.start_with?"adaptrex/") puts(("'" + responseFolder.split("/")[0] + "' is a reserved folder name").err) return promptForPagePath end if not response.validate?(/\A[a-z][a-z0-9\/\-\_]*\z/) puts(("Must be lowercase letters, numbers, underscore (_) or dash (-)").err) return promptForPagePath end if not @appConfig.pages[response].nil? puts "An app (page) already exists at that path".err return promptForPagePath end return response end |
#promptSDKType ⇒ Object
Prompt for the SDK Type To use for this page
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/adaptrex/generate.rb', line 193 def promptSDKType default = "1" if not @appConfig.lastSDK.nil? if @appConfig.lastSDK == "ext" then default = "1" else default = "2" end end print "Which type of page do you want to create? [" + default + "] : " response = STDIN.gets.chomp if response == "" then response = default end if response == "1" then return "ext" end if response == "2" then return "touch" end puts "Invalid selection. Enter a number from 1 to 2".err return promptSDKType end |