Class: Wizard
- Inherits:
-
Object
- Object
- Wizard
- Defined in:
- lib/occs-wizard.rb
Constant Summary collapse
- VERSION =
1
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#created_by ⇒ Object
Returns the value of attribute created_by.
-
#description ⇒ Object
Returns the value of attribute description.
-
#developer_id ⇒ Object
Returns the value of attribute developer_id.
-
#extension_id ⇒ Object
Returns the value of attribute extension_id.
-
#extension_name ⇒ Object
Returns the value of attribute extension_name.
Instance Method Summary collapse
-
#create_display_template_file(directory) ⇒ Object
create the display.template file.
-
#create_ext_json_file(directory) ⇒ Object
crate the ext.json file.
-
#create_js_file(directory) ⇒ Object
create the javascript file.
-
#create_less_file(directory) ⇒ Object
create the less file.
-
#create_project_structure ⇒ Object
Project Structure.
-
#create_widget_json_file(directory) ⇒ Object
create the file widget.json.
- #get_created_at ⇒ Object
- #get_created_by ⇒ Object
- #get_description ⇒ Object
- #get_developer_id ⇒ Object
- #get_extension_id ⇒ Object
- #get_extension_name ⇒ Object
- #get_user_input ⇒ Object
-
#initialize ⇒ Wizard
constructor
A new instance of Wizard.
- #set_created_at ⇒ Object
- #set_created_by(name = "OCCS Wizard Developer") ⇒ Object
- #set_description(desc) ⇒ Object
- #set_developer_id(dev_id) ⇒ Object
- #set_extension_id(ext) ⇒ Object
- #set_extension_name(ext_name) ⇒ Object
Constructor Details
#initialize ⇒ Wizard
Returns a new instance of Wizard.
241 242 243 |
# File 'lib/occs-wizard.rb', line 241 def initialize self.get_user_input end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/occs-wizard.rb', line 6 def created_at @created_at end |
#created_by ⇒ Object
Returns the value of attribute created_by.
6 7 8 |
# File 'lib/occs-wizard.rb', line 6 def created_by @created_by end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/occs-wizard.rb', line 6 def description @description end |
#developer_id ⇒ Object
Returns the value of attribute developer_id.
6 7 8 |
# File 'lib/occs-wizard.rb', line 6 def developer_id @developer_id end |
#extension_id ⇒ Object
Returns the value of attribute extension_id.
6 7 8 |
# File 'lib/occs-wizard.rb', line 6 def extension_id @extension_id end |
#extension_name ⇒ Object
Returns the value of attribute extension_name.
6 7 8 |
# File 'lib/occs-wizard.rb', line 6 def extension_name @extension_name end |
Instance Method Details
#create_display_template_file(directory) ⇒ Object
create the display.template file
103 104 105 106 107 108 109 110 |
# File 'lib/occs-wizard.rb', line 103 def create_display_template_file(directory) html = %{<!-- Template File -->\n <div class="myWidget">Hello World</div>} File.open(directory, "w") do |f| f.write(html) end end |
#create_ext_json_file(directory) ⇒ Object
crate the ext.json file
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/occs-wizard.rb', line 65 def create_ext_json_file(directory) ext_json = { extensionID: self.get_extension_id, developerID: self.get_developer_id, createdBy: self.created_by, name: self.get_extension_name, version: VERSION, timeCreated: self.get_created_at, description: self.get_description } # write the file File.open(directory,"w") do |f| # call the convert_to_json private method and write a json file f.write(convert_to_json(ext_json)) end end |
#create_js_file(directory) ⇒ Object
create the javascript file
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 |
# File 'lib/occs-wizard.rb', line 123 def create_js_file(directory) js = %{// Javascript widget file\n define(\n // Dependencies\n ['jquery', 'knockout'],\n // Module Implementation\n function($, ko) {\n // We recommend enabling strict checking mode\n 'use strict';\n // Private variables and functions can be defined here...\n var SOME_CONSTANT = 1024;\n var privateMethod = function () {\n // ...\n };\n return {\n // Widget JS\n onLoad: function(widget) {},\n // Some member variables...\n // Some public methods...\n }\n });} File.open(directory, "w") do |f| f.write(js) end end |
#create_less_file(directory) ⇒ Object
create the less file
113 114 115 116 117 118 119 120 |
# File 'lib/occs-wizard.rb', line 113 def create_less_file(directory) less = %{/* Widget CSS Less */\n .myWidget {}} File.open(directory, "w") do |f| f.write(less) end end |
#create_project_structure ⇒ Object
Project Structure
151 152 153 154 155 156 157 158 159 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 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/occs-wizard.rb', line 151 def create_project_structure # create the project date self.set_created_at # go back one dir Dir.chdir('..') raise Exception, "Folder #{self.extension_name} already exists" unless !File.directory?("#{self.extension_name}") # make a new root dir with the extension name FileUtils.mkdir(self.extension_name) # enter inside the new root dirt Dir.chdir("#{self.extension_name}") # create the widget folder FileUtils.mkdir('widget') # create the file ext.json self.create_ext_json_file("ext.json") # enter inside widget folder Dir.chdir('./widget') # create the extension name folder with no spaces and lowered FileUtils.mkdir(self.get_extension_name) # enter inside the extensionname folder Dir.chdir("./#{self.get_extension_name }") # make the template folder FileUtils.mkdir("templates") # make the js folder FileUtils.mkdir("js") # make the less folder FileUtils.mkdir("less") # write the widget.json file self.("widget.json") # move into the templates folder Dir.chdir("./templates") # write the display.template file self.create_display_template_file("display.template") # move back one dir Dir.chdir("..") # move inside the less folder Dir.chdir("./less") # write the less file self.create_less_file("widget.less") # move back one dir Dir.chdir("..") # move inside the js folder Dir.chdir("./js") # write the js file self.create_js_file("widget-#{self.get_extension_name}-js.js") # move back one dir Dir.chdir("..") # create the config folder Dir.mkdir("config") end |
#create_widget_json_file(directory) ⇒ Object
create the file widget.json
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/occs-wizard.rb', line 83 def (directory) = { name: self.get_extension_name, version: VERSION, global: false, javascript: "widget-#{self.get_extension_name}-js", pageTypes: ["home"], imports: ["products"], jsEditable: true, config: {} } # write the file File.open(directory,"w") do |f| # call the convert_to_json private method and write a json file f.write(convert_to_json()) end end |
#get_created_at ⇒ Object
34 35 36 |
# File 'lib/occs-wizard.rb', line 34 def get_created_at self.created_at end |
#get_created_by ⇒ Object
42 43 44 |
# File 'lib/occs-wizard.rb', line 42 def get_created_by self.created_by end |
#get_description ⇒ Object
60 61 62 |
# File 'lib/occs-wizard.rb', line 60 def get_description self.description end |
#get_developer_id ⇒ Object
23 24 25 |
# File 'lib/occs-wizard.rb', line 23 def get_developer_id self.developer_id end |
#get_extension_id ⇒ Object
14 15 16 |
# File 'lib/occs-wizard.rb', line 14 def get_extension_id self.extension_id end |
#get_extension_name ⇒ Object
51 52 53 |
# File 'lib/occs-wizard.rb', line 51 def get_extension_name ext_name = self.extension_name.delete(' ').downcase end |
#get_user_input ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/occs-wizard.rb', line 202 def get_user_input puts "\n" puts ".:: OCCS Widget Wizard ::." puts "\n" puts "Please have a look at the Oracle Commerce Cloud official documentation for more info" puts "https://goo.gl/i5d6us" puts "\n" print "Please enter the extension id: " dev_id = gets.chomp self.set_extension_id(dev_id) puts "\n" print "Please enter your developer id: " dev_id = gets.chomp self.set_developer_id(dev_id) puts "\n" print "Enter the developer name: " dev_name = gets.chomp self.set_created_by(dev_name) puts "\n" print "Enter the extension name: " ext_name = gets.chomp self.set_extension_name(ext_name) puts "\n" print "Enter the extension description: " ext_desc = gets.chomp self.set_description(ext_desc) puts "\n" begin self.create_project_structure puts "\n" puts "Project '#{self.extension_name}' was successfully created at #{Dir.pwd}" puts "\n" rescue puts "Sorry but there was an error creating your widget structure, please try again" end end |
#set_created_at ⇒ Object
27 28 29 30 31 32 |
# File 'lib/occs-wizard.rb', line 27 def set_created_at time = Time.now current = time.to_s.scan(/\w+/) today = "#{current[0]}-#{current[1]}-#{current[2]}" self.created_at = today end |
#set_created_by(name = "OCCS Wizard Developer") ⇒ Object
38 39 40 |
# File 'lib/occs-wizard.rb', line 38 def set_created_by(name = "OCCS Wizard Developer") self.created_by = name end |
#set_description(desc) ⇒ Object
55 56 57 58 |
# File 'lib/occs-wizard.rb', line 55 def set_description(desc) raise ArgumentError, 'Extension description cannot be empty' unless desc.size > 0 self.description = desc end |
#set_developer_id(dev_id) ⇒ Object
18 19 20 21 |
# File 'lib/occs-wizard.rb', line 18 def set_developer_id(dev_id) raise ArgumentError, 'Developer ID value is not valid, please read the documentation for further details' unless dev_id.size >= 8 self.developer_id = dev_id end |
#set_extension_id(ext) ⇒ Object
9 10 11 12 |
# File 'lib/occs-wizard.rb', line 9 def set_extension_id(ext) raise ArgumentError, 'Argument is not a valid OCCS extension id, please read the documentation for further details' unless ext.size == 36 && ext.is_a?(String) self.extension_id = ext end |
#set_extension_name(ext_name) ⇒ Object
46 47 48 49 |
# File 'lib/occs-wizard.rb', line 46 def set_extension_name(ext_name) raise ArgumentError, 'Extension name cannot be empty' unless ext_name.size > 0 self.extension_name = ext_name end |