shop 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +17 -1
- data/lib/shop/color.rb +54 -0
- data/lib/shop/command.rb +108 -10
- data/lib/shop/platform.rb +39 -0
- data/lib/shop/shopconfig.rb +21 -9
- data/lib/shop.rb +3 -1
- data/shop.gemspec +6 -1
- data/templates/controller-1.4.php +18 -0
- data/templates/controller.php +22 -0
- data/templates/page.php +4 -0
- data/templates/shop +3 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWI1Y2YyMzA2ODA5OGQwNWFlYWE4ZWU0MjlkODc1MjZiNTkxZDQ2Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzgwNWNmYWQwZjJkNDNjZGVkMThhMGZiOGEwMDFlNThkMGFiYWU0ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2MxY2NhM2RmM2M5ZmVjNTU5ZmI1ZDU0ZWU4MzgwOTdjZjA2OTgzODFiODIx
|
10
|
+
Y2U1NjRlMWRjYmNjOTkxNjVhMmFiNTEzNzY3OThkY2QyMmYxNjM5YWFmMDRl
|
11
|
+
YmQ4YTVmM2RhYzk3ZTdlMjdjMjU1MDFkM2EwODdhYmJiMDhmODc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTNlNzg5OGNlZjAwOTI0NGM1MTI1ZThkNzY2ZDQyNTk5MWJiYjgwZmFlNTEz
|
14
|
+
MGIyNGUxOWQ0OTk2ZmU2MGY2ZDg5ZjYxMGQzZDk3MWZjY2NmNzlkNmQ0YzVi
|
15
|
+
YTg0ODcwY2I1ZjIwMjRiMDUxYTFlYjE2ZjZkMTI1MGQwNjMxYzc=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -64,6 +64,17 @@ Creates overrides files for controllers and classes.
|
|
64
64
|
# generate an override for the Product class
|
65
65
|
shop override class Product
|
66
66
|
|
67
|
+
### New Pages
|
68
|
+
|
69
|
+
You can generate new pages for PrestaShop easily with the `controller` command. This will create the controller, template, CSS and JS files you need to create a new page.
|
70
|
+
|
71
|
+
shop controller <page-name>
|
72
|
+
|
73
|
+
# example:
|
74
|
+
shop controller CustomPage
|
75
|
+
|
76
|
+
This task is adapted to work on PrestaShop 1.5 and 1.4.
|
77
|
+
|
67
78
|
### Modules
|
68
79
|
|
69
80
|
**The modules related tasks will need the Shop project to be [initialized](https://github.com/romainberger/shop)**
|
@@ -142,7 +153,12 @@ You can get a list of the available commands with the help:
|
|
142
153
|
|
143
154
|
## Configuration
|
144
155
|
|
145
|
-
You can use a configuration file to automate some values in the templates files created (modules and for the installation of PrestaShop).
|
156
|
+
You can use a configuration file to automate some values in the templates files created (modules and for the installation of PrestaShop).
|
157
|
+
You can edit this file with the command
|
158
|
+
|
159
|
+
shop edit
|
160
|
+
|
161
|
+
It will open the config file in your `$EDITOR`
|
146
162
|
|
147
163
|
## Compatibility
|
148
164
|
|
data/lib/shop/color.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Shamelessly stolen from https://github.com/holman/boom
|
2
|
+
|
3
|
+
module Shop
|
4
|
+
# Color collects some methods for colorizing terminal output.
|
5
|
+
module Color
|
6
|
+
extend self
|
7
|
+
|
8
|
+
CODES = {
|
9
|
+
:reset => "\e[0m",
|
10
|
+
:cyan => "\e[36m",
|
11
|
+
:magenta => "\e[35m",
|
12
|
+
:red => "\e[31m",
|
13
|
+
:yellow => "\e[33m",
|
14
|
+
:green => "\e[32m"
|
15
|
+
}
|
16
|
+
|
17
|
+
# Tries to enable Windows support if on that platform.
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
def self.included(other)
|
21
|
+
if RUBY_PLATFORM =~ /win32/ || RUBY_PLATFORM =~ /mingw32/
|
22
|
+
require 'Win32/Console/ANSI'
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
# Oh well, we tried.
|
26
|
+
end
|
27
|
+
|
28
|
+
# Wraps the given string in ANSI color codes
|
29
|
+
#
|
30
|
+
# string - The String to wrap.
|
31
|
+
# color_code - The String representing he ANSI color code
|
32
|
+
#
|
33
|
+
# Examples
|
34
|
+
#
|
35
|
+
# colorize("Boom!", :magenta)
|
36
|
+
# # => "\e[35mBoom!\e[0m"
|
37
|
+
#
|
38
|
+
# Returns the wrapped String unless the the platform is windows and
|
39
|
+
# does not have Win32::Console, in which case, returns the String.
|
40
|
+
def colorize(string, color_code)
|
41
|
+
if !defined?(Win32::Console) && !!(RUBY_PLATFORM =~ /win32/ || RUBY_PLATFORM =~ /mingw32/)
|
42
|
+
# looks like this person doesn't have Win32::Console and is on windows
|
43
|
+
# just return the uncolorized string
|
44
|
+
return string
|
45
|
+
end
|
46
|
+
"#{CODES[color_code] || color_code}#{string}#{CODES[:reset]}"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Set up shortcut methods to all the codes define in CODES.
|
50
|
+
self.class_eval(CODES.keys.reject {|color| color == :reset }.map do |color|
|
51
|
+
"def #{color}(string); colorize(string, :#{color}); end"
|
52
|
+
end.join("\n"))
|
53
|
+
end
|
54
|
+
end
|
data/lib/shop/command.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
module Shop
|
4
4
|
class Command
|
5
5
|
class << self
|
6
|
+
include Shop::Color
|
6
7
|
|
7
8
|
def template
|
8
9
|
Template.new
|
@@ -13,11 +14,23 @@ module Shop
|
|
13
14
|
if init?
|
14
15
|
return File.read('.shop')
|
15
16
|
else
|
16
|
-
puts "Project not initialized.
|
17
|
+
puts "#{red("Error")}: Project not initialized."
|
18
|
+
puts "Please run #{cyan("shop init <theme-name>")}"
|
17
19
|
exit
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
# Returns the version of Prestashop installed
|
24
|
+
def psVersion
|
25
|
+
if !installed?
|
26
|
+
puts "PrestaShop does not seem to be installed"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
line = File.read("config/settings.inc.php")[/^\s*define\('_PS_VERSION_',\s*.*\)/]
|
31
|
+
line.match(/.*define\('_PS_VERSION_',\s*\s*['"](.*)['"]\)/)[1]
|
32
|
+
end
|
33
|
+
|
21
34
|
def execute(*args)
|
22
35
|
command = args.shift
|
23
36
|
major = args.shift
|
@@ -33,15 +46,17 @@ module Shop
|
|
33
46
|
return init(major) if command == 'init'
|
34
47
|
return install if command == 'install'
|
35
48
|
return shopModule(major, minor, extra) if command == 'module'
|
36
|
-
return override(major,
|
49
|
+
return override(major, major, extra) if command == 'override'
|
50
|
+
return controller(major) if command == 'controller'
|
37
51
|
return clean(major) if command == 'clean'
|
38
52
|
return jshint(major) if command == 'jshint'
|
39
53
|
return makefile if command == 'makefile'
|
54
|
+
return edit if command == 'edit'
|
40
55
|
return version if command == "-v"
|
41
56
|
return version if command == "--version"
|
42
57
|
return help if command == 'help'
|
43
58
|
|
44
|
-
puts "\
|
59
|
+
puts "\n#{red("Error")}: Command not found"
|
45
60
|
return help
|
46
61
|
end
|
47
62
|
|
@@ -79,12 +94,16 @@ module Shop
|
|
79
94
|
done
|
80
95
|
end
|
81
96
|
|
97
|
+
# Returns if the framework is already installed
|
98
|
+
def installed?
|
99
|
+
File.exists?('config/settings.inc.php')
|
100
|
+
end
|
101
|
+
|
82
102
|
# Runs the Prestashop install CLI but with a nice prompt
|
83
103
|
#
|
84
104
|
# See http://doc.prestashop.com/display/PS15/Installing+PrestaShop+using+the+command+line
|
85
105
|
def install
|
86
|
-
|
87
|
-
if File.exists?('config/settings.inc.php')
|
106
|
+
if installed?
|
88
107
|
puts "PrestaShop appears to be already installed"
|
89
108
|
exit
|
90
109
|
end
|
@@ -137,7 +156,7 @@ module Shop
|
|
137
156
|
# Init the project
|
138
157
|
def init(name)
|
139
158
|
if name.nil?
|
140
|
-
puts "Error: Please specify the name of the theme"
|
159
|
+
puts "#{red("Error:")} Please specify the name of the theme"
|
141
160
|
return puts " $ shop init <theme-name>"
|
142
161
|
end
|
143
162
|
|
@@ -170,7 +189,7 @@ module Shop
|
|
170
189
|
|
171
190
|
filepath = "#{path}/#{extra}.tpl"
|
172
191
|
if File.exists?(filepath)
|
173
|
-
puts "File already exists"
|
192
|
+
puts "#{red("Error:")} File already exists"
|
174
193
|
exit
|
175
194
|
else
|
176
195
|
File.open(filepath, "w") do; end
|
@@ -184,7 +203,7 @@ module Shop
|
|
184
203
|
filepath = "#{path}/#{minor}.css"
|
185
204
|
|
186
205
|
if File.exists?(filepath)
|
187
|
-
puts "File already exists"
|
206
|
+
puts "#{red("Error:")} File already exists"
|
188
207
|
exit
|
189
208
|
elsif
|
190
209
|
File.open(filepath, "w") do; end
|
@@ -248,13 +267,79 @@ module Shop
|
|
248
267
|
content = "<?php\n\nclass #{name} extends #{name}Core {\n\n}\n"
|
249
268
|
|
250
269
|
if !File.directory?('override')
|
251
|
-
return puts "You need to be at the root of your Prestashop site"
|
270
|
+
return puts "#{red("Error:")} You need to be at the root of your Prestashop site"
|
252
271
|
end
|
253
272
|
|
254
273
|
File.open(path, 'w') do |f|
|
255
274
|
f.write(content)
|
256
275
|
end
|
257
276
|
|
277
|
+
clean("class")
|
278
|
+
|
279
|
+
done
|
280
|
+
end
|
281
|
+
|
282
|
+
# Creates a new page with controller and files associated
|
283
|
+
#
|
284
|
+
# @todo adapt this to work with PS 1.4 (needs a .php file in the root dir)
|
285
|
+
def controller(major)
|
286
|
+
if major.nil?
|
287
|
+
puts "#{red("Error")}: Please provide a name for the page"
|
288
|
+
exit
|
289
|
+
end
|
290
|
+
theme
|
291
|
+
version = psVersion
|
292
|
+
version = version[0, 3]
|
293
|
+
|
294
|
+
name = major.downcase
|
295
|
+
controller_name = "#{name.capitalize}Controller"
|
296
|
+
filename = "#{controller_name}.php"
|
297
|
+
if version.to_f >= 1.5
|
298
|
+
controller_path = "controllers/front/#{filename}"
|
299
|
+
elsif version == "1.4"
|
300
|
+
controller_path = "controllers/#{filename}"
|
301
|
+
end
|
302
|
+
|
303
|
+
|
304
|
+
if File.exists?(controller_path)
|
305
|
+
puts "#{red("Error")}: Controller already exists"
|
306
|
+
exit
|
307
|
+
end
|
308
|
+
|
309
|
+
# datas for templates
|
310
|
+
datas = {
|
311
|
+
'controller_name' => controller_name,
|
312
|
+
'name' => name.downcase
|
313
|
+
}
|
314
|
+
|
315
|
+
# For PS 1.4 creates a php file a the root
|
316
|
+
# and use the appropriate template
|
317
|
+
if version[0, 3] == "1.4"
|
318
|
+
content = template.template("page.php", datas)
|
319
|
+
File.open("#{name.downcase}.php", "w") do |f|
|
320
|
+
f.write(content)
|
321
|
+
end
|
322
|
+
controllerContent = template.template("controller-1.4.php", datas)
|
323
|
+
else
|
324
|
+
controllerContent = template.template("controller.php", datas)
|
325
|
+
end
|
326
|
+
|
327
|
+
File.open(controller_path, "w") do |f|
|
328
|
+
f.write(controllerContent)
|
329
|
+
end
|
330
|
+
|
331
|
+
files = [
|
332
|
+
"themes/#{theme}/#{name}.tpl",
|
333
|
+
"themes/#{theme}/css/#{name}.css",
|
334
|
+
"themes/#{theme}/js/#{name}.js"
|
335
|
+
]
|
336
|
+
|
337
|
+
files.each do |f|
|
338
|
+
File.open(f, "w") do; end
|
339
|
+
end
|
340
|
+
|
341
|
+
clean("class")
|
342
|
+
|
258
343
|
done
|
259
344
|
end
|
260
345
|
|
@@ -269,6 +354,11 @@ module Shop
|
|
269
354
|
File.delete(f)
|
270
355
|
end
|
271
356
|
elsif major == 'class'
|
357
|
+
version = psVersion
|
358
|
+
if version[0, 3] == "1.4"
|
359
|
+
return
|
360
|
+
end
|
361
|
+
|
272
362
|
print "Cleaning class index... "
|
273
363
|
index = "cache/class_index.php"
|
274
364
|
if File.exists?(index)
|
@@ -321,7 +411,12 @@ module Shop
|
|
321
411
|
end
|
322
412
|
|
323
413
|
def done
|
324
|
-
puts "✔ Done"
|
414
|
+
puts "#{green("✔ Done")}"
|
415
|
+
end
|
416
|
+
|
417
|
+
def edit
|
418
|
+
config = ShopConfig.new
|
419
|
+
puts config.edit
|
325
420
|
end
|
326
421
|
|
327
422
|
# Returns the version of Shop
|
@@ -343,6 +438,9 @@ module Shop
|
|
343
438
|
shop module template <name> <hook> Creates a template for a given module / hook
|
344
439
|
shop module css <name> Creates an override for a module css
|
345
440
|
|
441
|
+
shop controller <controller-name> Creates a new page with a controller and
|
442
|
+
assets needed
|
443
|
+
|
346
444
|
shop override controller <name> Creates an override for a controller
|
347
445
|
shop override controller <name> admin Creates an override for an admin controller
|
348
446
|
shop override class <name> Creates an override for a class
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# Partly stolen from https://github.com/holman/boom
|
4
|
+
|
5
|
+
module Shop
|
6
|
+
class Platform
|
7
|
+
# Public: tests if currently running on darwin.
|
8
|
+
#
|
9
|
+
# Returns true if running on darwin (MacOS X), else false
|
10
|
+
def darwin?
|
11
|
+
!!(RUBY_PLATFORM =~ /darwin/)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Public: tests if currently running on windows.
|
15
|
+
#
|
16
|
+
# Apparently Windows RUBY_PLATFORM can be 'win32' or 'mingw32'
|
17
|
+
#
|
18
|
+
# Returns true if running on windows (win32/mingw32), else false
|
19
|
+
def windows?
|
20
|
+
!!(RUBY_PLATFORM =~ /mswin|mingw/)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: returns the command used to open a file or URL
|
24
|
+
# for the current platform.
|
25
|
+
#
|
26
|
+
# Currently only supports MacOS X and Linux with `xdg-open`.
|
27
|
+
#
|
28
|
+
# Returns a String with the bin
|
29
|
+
def open_command
|
30
|
+
if darwin?
|
31
|
+
'open'
|
32
|
+
elsif windows?
|
33
|
+
'start'
|
34
|
+
else
|
35
|
+
'xdg-open'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/shop/shopconfig.rb
CHANGED
@@ -33,12 +33,6 @@ module Shop
|
|
33
33
|
get_config
|
34
34
|
end
|
35
35
|
|
36
|
-
# Set a value and save the config
|
37
|
-
def set(key, value)
|
38
|
-
config[key] = value
|
39
|
-
save
|
40
|
-
end
|
41
|
-
|
42
36
|
def bootstrap
|
43
37
|
return if File.exists?(CONFIG_FILE)
|
44
38
|
path = template.template_path('shop')
|
@@ -50,9 +44,27 @@ module Shop
|
|
50
44
|
return @config
|
51
45
|
end
|
52
46
|
|
53
|
-
#
|
54
|
-
|
55
|
-
|
47
|
+
# Public: opens the config file in an editor for you to edit. Uses the
|
48
|
+
# $EDITOR environment variable, or %EDITOR% on Windows for editing.
|
49
|
+
# This method is designed to handle multiple platforms.
|
50
|
+
# If $EDITOR is nil, try to open using the open_command.
|
51
|
+
#
|
52
|
+
# Stolen from https://github.com/holman/boom and adapted
|
53
|
+
#
|
54
|
+
# Returns a String with a helpful message.
|
55
|
+
def edit
|
56
|
+
platform = Platform.new
|
57
|
+
unless $EDITOR.nil?
|
58
|
+
unless platform.windows?
|
59
|
+
system("`echo $EDITOR` #{CONFIG_FILE} &")
|
60
|
+
else
|
61
|
+
system("start %EDITOR% #{CONFIG_FILE}")
|
62
|
+
end
|
63
|
+
else
|
64
|
+
system("#{platform.open_command} #{CONFIG_FILE}")
|
65
|
+
end
|
66
|
+
|
67
|
+
"Make your edits, and do be sure to save."
|
56
68
|
end
|
57
69
|
end
|
58
70
|
end
|
data/lib/shop.rb
CHANGED
data/shop.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'shop'
|
16
|
-
s.version = '0.1.
|
16
|
+
s.version = '0.1.6'
|
17
17
|
s.date = '2013-09-23'
|
18
18
|
s.rubyforge_project = 'shop'
|
19
19
|
|
@@ -70,8 +70,13 @@ Gem::Specification.new do |s|
|
|
70
70
|
lib/shop/shopconfig.rb
|
71
71
|
lib/shop/command.rb
|
72
72
|
lib/shop/template.rb
|
73
|
+
lib/shop/color.rb
|
74
|
+
lib/shop/platform.rb
|
73
75
|
templates/Makefile
|
74
76
|
templates/module.php
|
77
|
+
templates/controller.php
|
78
|
+
templates/controller-1.4.php
|
79
|
+
templates/page.php
|
75
80
|
templates/shop
|
76
81
|
]
|
77
82
|
# = MANIFEST =
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class {{controller_name}}Core extends FrontController {
|
4
|
+
|
5
|
+
public function setMedia() {
|
6
|
+
parent::setMedia();
|
7
|
+
|
8
|
+
Tools::addCSS(_THEME_CSS_DIR_.'{{name}}.css');
|
9
|
+
Tools::addJS(_THEME_JS_DIR_.'{{name}}.js');
|
10
|
+
}
|
11
|
+
|
12
|
+
public function displayContent() {
|
13
|
+
parent::displayContent();
|
14
|
+
|
15
|
+
self::$smarty->display(_PS_THEME_DIR_.'{{name}}.tpl');
|
16
|
+
}
|
17
|
+
|
18
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class {{controller_name}}Core extends FrontController {
|
4
|
+
|
5
|
+
public function setMedia() {
|
6
|
+
parent::setMedia();
|
7
|
+
|
8
|
+
$this->addCSS(_THEME_CSS_DIR_.'{{name}}.css');
|
9
|
+
$this->addJS(_THEME_JS_DIR_.'{{name}}.js');
|
10
|
+
}
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Assign template vars related to page content
|
14
|
+
* @see FrontController::initContent()
|
15
|
+
*/
|
16
|
+
public function initContent() {
|
17
|
+
parent::initContent();
|
18
|
+
|
19
|
+
$this->setTemplate(_PS_THEME_DIR_.'{{name}}.tpl');
|
20
|
+
}
|
21
|
+
|
22
|
+
}
|
data/templates/page.php
ADDED
data/templates/shop
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romain Berger
|
@@ -44,8 +44,13 @@ files:
|
|
44
44
|
- lib/shop/shopconfig.rb
|
45
45
|
- lib/shop/command.rb
|
46
46
|
- lib/shop/template.rb
|
47
|
+
- lib/shop/color.rb
|
48
|
+
- lib/shop/platform.rb
|
47
49
|
- templates/Makefile
|
48
50
|
- templates/module.php
|
51
|
+
- templates/controller.php
|
52
|
+
- templates/controller-1.4.php
|
53
|
+
- templates/page.php
|
49
54
|
- templates/shop
|
50
55
|
homepage: https://github.com/romainberger/shop
|
51
56
|
licenses:
|