maglove 2.0.4 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{vendor → assets}/autoprefixer.js +0 -0
- data/{data/maglove → assets}/export.haml +0 -0
- data/{data/maglove → assets}/hpub/index.css +0 -0
- data/{data/maglove → assets}/hpub/index.haml +0 -0
- data/{data/maglove → assets}/hpub/page.haml +0 -0
- data/{data/maglove → assets}/index.haml +0 -0
- data/{data/maglove → assets}/maglove.css +0 -0
- data/{data/maglove → assets}/maglove.haml +0 -0
- data/{data/maglove → assets}/maglove.js +1 -1
- data/{data/maglove → assets}/scaffold/base/base.coffee +0 -0
- data/{data/maglove → assets}/scaffold/base/base.less +0 -0
- data/{data/maglove → assets}/scaffold/base/images/base/loading-bars.svg +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/animations.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/blockquotes.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/buttons.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/code.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/forms.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/global.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/grid-minimal.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/grid-non-responsive.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/grid.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/helpers.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/images.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/lists.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/mixins.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/print.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/resets.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/base/tables.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/core/alignments.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/core/cleanup.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/core/editor.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/core/typography.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/flex-video.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/animated.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/bordered-pulled.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/core.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/fixed-width.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/font-awesome.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/icons.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/larger.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/list.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/mixins.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/rotated-flipped.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/stacked.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/variables.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/image-loader.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/vendor/magnific-popup.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/banner.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/button.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/callout.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/columns.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/container.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/feedback.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/heading.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/horizontal_rule.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/image.less +0 -0
- data/{data/maglove → assets}/scaffold/base/less/widgets/paragraph.less +0 -0
- data/{data/maglove → assets}/scaffold/base/variables.less +0 -0
- data/{data/maglove → assets}/scaffold/base/vendor/jquery.js +0 -0
- data/{data/maglove → assets}/scaffold/theme/images/logo.png +0 -0
- data/{data/maglove → assets}/scaffold/theme/images/pattern/symphony.png +0 -0
- data/{data/maglove → assets}/scaffold/theme/less/base/variables.less +0 -0
- data/{data/maglove → assets}/scaffold/theme/templates/article-01.haml +3 -3
- data/{data/maglove → assets}/scaffold/theme/templates/cover.haml +0 -0
- data/{data/maglove → assets}/scaffold/theme/templates/toc.haml +1 -1
- data/{data/maglove → assets}/scaffold/theme/templates/toc.yml +0 -0
- data/{data/maglove → assets}/scaffold/theme/theme.coffee +0 -0
- data/{data/maglove → assets}/scaffold/theme/theme.less +0 -0
- data/{data/maglove → assets}/thumbnail.haml +0 -0
- data/{data/maglove → assets}/thumbnail.js +0 -0
- data/bin/maglove +0 -6
- data/lib/magloft/api_caller.rb +12 -12
- data/lib/magloft/remote_resource.rb +17 -17
- data/lib/maglove.rb +19 -19
- data/lib/maglove/asset/theme.rb +7 -6
- data/lib/maglove/commands/assets.rb +61 -44
- data/lib/maglove/commands/base.rb +5 -1
- data/lib/maglove/commands/fonts.rb +9 -6
- data/lib/maglove/commands/main.rb +3 -1
- data/lib/maglove/commands/theme.rb +63 -58
- data/lib/maglove/middleware/live_reload.rb +19 -11
- data/lib/maglove/server.rb +18 -8
- data/lib/maglove/theme.rb +27 -0
- data/lib/maglove/tilt/coffee_template.rb +1 -1
- data/lib/maglove/tilt/haml_template.rb +2 -3
- data/lib/maglove/tilt/js_template.rb +1 -2
- data/lib/maglove/tilt/scss_template.rb +3 -9
- data/lib/maglove/tilt/yaml_template.rb +2 -3
- data/lib/maglove/version.rb +1 -1
- data/lib/powersnap.rb +1 -3
- metadata +164 -155
- data/.gitignore +0 -9
- data/.rubocop.yml +0 -157
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -206
- data/README.md +0 -26
- data/lib/block_resolver.rb +0 -6
- data/lib/maglove/application.rb +0 -58
- data/lib/maglove/phantom_script.rb +0 -44
- data/lib/maglove/workspace.rb +0 -41
- data/lib/workspace.rb +0 -11
- data/lib/workspace/workspace_dir.rb +0 -98
- data/lib/workspace/workspace_dir/archive.rb +0 -18
- data/lib/workspace/workspace_file.rb +0 -127
- data/lib/workspace/workspace_file/archive.rb +0 -45
- data/lib/workspace/workspace_file/media.rb +0 -19
- data/lib/workspace/workspace_file/net.rb +0 -18
- data/lib/workspace/workspace_file/parse.rb +0 -21
- data/maglove.gemspec +0 -45
@@ -18,49 +18,49 @@ module MagLove
|
|
18
18
|
desc "clean", "Clean theme dist directory"
|
19
19
|
def clean
|
20
20
|
info("▸ Cleaning up Theme Directory")
|
21
|
-
|
21
|
+
theme.dist_dir.clean
|
22
22
|
end
|
23
23
|
|
24
24
|
desc "images", "Copy images"
|
25
25
|
def images
|
26
26
|
info("▸ Copying Images")
|
27
|
-
|
27
|
+
theme.base_dir.children("images/**/*.{jpg,png,gif,svg}").each do |file|
|
28
28
|
debug("~> Copying #{file}")
|
29
|
-
|
29
|
+
MagLove::Asset::Theme.new(file.path, { base: true }).write!
|
30
30
|
end
|
31
|
-
|
31
|
+
theme.src_dir.children("images/**/*.{jpg,png,gif,svg}").each do |file|
|
32
32
|
debug("~> Copying #{file}")
|
33
|
-
file.
|
33
|
+
MagLove::Asset::Theme.new(file.path, { base: false }).write!
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
desc "videos", "Copy videos"
|
38
38
|
def videos
|
39
39
|
info("▸ Copying Videos")
|
40
|
-
|
40
|
+
theme.src_dir.children("videos/**/*.{mp4,webm,ogg}").each do |file|
|
41
41
|
debug("~> Copying #{file}")
|
42
|
-
file.
|
42
|
+
MagLove::Asset::Theme.new(file.path, { base: false }).write!
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
desc "
|
45
|
+
|
46
|
+
desc "optimizeimages", "Optimize images"
|
47
47
|
option :percent, type: :numeric, required: true, default: 25
|
48
|
-
def
|
49
|
-
require "image_optim"
|
50
|
-
optimizer = ImageOptim.new(nice: 20, pngout: true, optipng: {level: 5}, jpegoptim: {allow_lossy: true, max_quality: 80})
|
48
|
+
def optimizeimages
|
51
49
|
info("▸ Optimizing Images")
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
50
|
+
require "workspace-media"
|
51
|
+
Workspace.tmpdir do |tmpdir|
|
52
|
+
theme.src_dir.children("images/**/*.{jpg,png,gif}").each do |file|
|
53
|
+
tmp_file = tmpdir.file(file.name)
|
54
|
+
file.copy(tmp_file)
|
55
|
+
old_size = tmp_file.size
|
56
|
+
tmp_file.optimize!(image_max_width: 1536, quality: 75, convert_jpg: false, optimize: true)
|
57
|
+
new_size = tmp_file.size
|
58
|
+
compression = new_size.to_f / old_size.to_f
|
59
|
+
if compression < 0.99
|
60
|
+
info("~> #{file.relative_path} optimized #{((1 - compression) * 100).to_i}% (#{old_size / 1000}kb to #{new_size / 1000}kb)")
|
61
|
+
tmp_file.move(file)
|
62
|
+
else
|
63
|
+
debug("~> #{file.relative_path} skipped #{((1 - compression) * 100).to_i}% (#{old_size / 1000}kb to #{new_size / 1000}kb)")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -69,56 +69,73 @@ module MagLove
|
|
69
69
|
desc "javascript", "Compile JavaScript"
|
70
70
|
def javascript
|
71
71
|
info("▸ Compiling JavaScript")
|
72
|
-
|
72
|
+
MagLove::Asset::Theme.new("theme.coffee", { base: false }).write!
|
73
73
|
end
|
74
74
|
|
75
75
|
desc "stylesheet", "Compile Stylesheet"
|
76
76
|
def stylesheet
|
77
77
|
info("▸ Compiling Stylesheet")
|
78
|
-
|
78
|
+
Maglove::Engine.configure do |config|
|
79
|
+
config.asset_uri = "."
|
80
|
+
end
|
81
|
+
file = theme.src_dir.children("theme.{scss,less}").first
|
82
|
+
MagLove::Asset::Theme.new(file.path, { base: false }).write!
|
79
83
|
end
|
80
84
|
|
81
85
|
desc "yaml", "Compile YAML Manifest"
|
82
86
|
def yaml
|
83
87
|
info("▸ Compiling YAML Manifest")
|
84
|
-
|
88
|
+
MagLove::Asset::Theme.new("theme.yml", { base: false }).write!
|
85
89
|
end
|
86
|
-
|
90
|
+
|
87
91
|
desc "compress", "Compress Assets for Distribution"
|
88
92
|
def compress
|
89
93
|
invoke(:javascript)
|
90
94
|
invoke(:stylesheet)
|
91
|
-
|
95
|
+
require 'cssminify'
|
96
|
+
require 'closure-compiler'
|
97
|
+
|
92
98
|
info("▸ Compressing JavaScript")
|
93
|
-
|
99
|
+
js_file = theme.dist_dir.file("theme.js")
|
100
|
+
js_file.write(Closure::Compiler.new.compile(js_file.read))
|
101
|
+
|
94
102
|
info("▸ Compressing Stylesheet")
|
95
|
-
|
103
|
+
css_file = theme.dist_dir.file("theme.css")
|
104
|
+
runtime = ExecJS.compile(Maglove.assets_dir.file("autoprefixer.js").read)
|
105
|
+
results = runtime.call("(function(css) { return autoprefixer.process(css).css; })", [css_file.read])
|
106
|
+
css_file.write(CSSminify.compress(results))
|
96
107
|
end
|
97
108
|
|
98
109
|
desc "templates", "Compile HAML Templates"
|
99
110
|
def templates
|
100
111
|
info("▸ Compiling HAML Templates")
|
101
|
-
|
102
|
-
|
112
|
+
Maglove::Engine.configure do |config|
|
113
|
+
config.asset_uri = "file://#{Workspace::Dir.new(Dir.pwd, 'dist').absolute_path}"
|
114
|
+
config.block_path = theme.src_dir.dir("blocks").to_s
|
115
|
+
end
|
116
|
+
theme.templates.each do |template|
|
103
117
|
debug "~> processing template #{template}"
|
104
|
-
template_file =
|
118
|
+
template_file = theme.src_dir.file("templates/#{template}.haml")
|
105
119
|
error!("~> Template '#{template}' does not exist!") if template_file.nil?
|
106
|
-
contents = template_file.
|
107
|
-
html_contents =
|
108
|
-
|
120
|
+
contents = MagLove::Asset::Theme.new(template_file.path, { base: false }).contents
|
121
|
+
html_contents = Maglove::Engine.render(Maglove.assets_dir.file("export.haml").read, theme: theme.identifier, contents: contents)
|
122
|
+
theme.dist_dir.file("templates/#{template}.html").write(html_contents)
|
109
123
|
end
|
110
124
|
end
|
111
125
|
|
112
126
|
desc "blocks", "Compile HAML Blocks"
|
113
127
|
def blocks
|
114
128
|
info("▸ Compiling HAML Blocks")
|
115
|
-
if
|
116
|
-
|
117
|
-
|
129
|
+
if theme.src_dir.dir("blocks").exists?
|
130
|
+
Maglove::Engine.configure do |config|
|
131
|
+
config.asset_uri = "file://#{Workspace::Dir.new(Dir.pwd, 'dist').absolute_path}"
|
132
|
+
config.block_path = theme.src_dir.dir("blocks").to_s
|
133
|
+
end
|
134
|
+
theme.src_dir.dir("blocks").children("**/*.haml").each do |block_file|
|
118
135
|
debug "~> processing block #{block_file.basename}"
|
119
|
-
contents = block_file.
|
120
|
-
html_contents =
|
121
|
-
|
136
|
+
contents = MagLove::Asset::Theme.new(block_file.path, { base: false }).contents
|
137
|
+
html_contents = Maglove::Engine.render(Maglove.assets_dir.file("export.haml").read, theme: theme.identifier, contents: contents)
|
138
|
+
theme.dist_dir.file("blocks/#{block_file.basename}.html").write(html_contents)
|
122
139
|
end
|
123
140
|
else
|
124
141
|
debug "~> no blocks available"
|
@@ -4,17 +4,21 @@ module MagLove
|
|
4
4
|
module Commands
|
5
5
|
class Base < Thor
|
6
6
|
include MagLove::Helper::LogHelper
|
7
|
-
include Workspace
|
8
7
|
|
9
8
|
def initialize(args, opts, config)
|
10
9
|
namespace = self.class.name.split("::").last.underscore
|
11
10
|
command = config[:current_command].name
|
12
11
|
Logging.mdc["full_command"] = "#{namespace}:#{command}"
|
13
12
|
super
|
13
|
+
theme.load(options.theme) if options.theme? and options.theme != theme.identifier
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
+
def theme
|
19
|
+
Maglove.theme
|
20
|
+
end
|
21
|
+
|
18
22
|
def magloft_api
|
19
23
|
@magloft_api ||= MagLoft::Api.client(options[:token])
|
20
24
|
end
|
@@ -19,7 +19,7 @@ module MagLove
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# 2: Generate stylesheets
|
22
|
-
|
22
|
+
info("▸ compiling fonts:")
|
23
23
|
FileUtils.touch("dist/fonts/fonts.css")
|
24
24
|
open("dist/fonts/fonts.css", 'wb') do |master_file|
|
25
25
|
font_map.each do |font_id, variants|
|
@@ -40,11 +40,14 @@ module MagLove
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "push", "Publish fonts to google cloud storage"
|
46
|
+
option :bucket, type: :string, default: "cdn.magloft.com"
|
47
|
+
def push
|
48
|
+
invoke(Fonts, :compile, [], {})
|
49
|
+
info("▸ pushing fonts to gcs")
|
50
|
+
`gsutil -m rsync -r dist/fonts/ gs://#{options.bucket}/fonts/`
|
48
51
|
end
|
49
52
|
|
50
53
|
private
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module MagLove
|
2
2
|
module Commands
|
3
3
|
class Main < Base
|
4
|
+
Maglove::Engine.register_widgets
|
5
|
+
|
4
6
|
desc "fonts SUBCOMMAND ...ARGS", "manage fonts"
|
5
7
|
subcommand "fonts", Commands::Fonts
|
6
8
|
|
@@ -12,7 +14,7 @@ module MagLove
|
|
12
14
|
|
13
15
|
desc "compile", "Compile all themes"
|
14
16
|
def compile
|
15
|
-
|
17
|
+
Workspace::Dir.new(Dir.pwd, "src/themes").children("*").each do |dir|
|
16
18
|
theme = dir.name
|
17
19
|
info("COMPILING THEME #{theme}")
|
18
20
|
invoke(Assets, :compile, [], theme: theme)
|
@@ -5,11 +5,11 @@ module MagLove
|
|
5
5
|
option :port, type: :string, default: "4000"
|
6
6
|
option :theme, type: :string, required: true, validator: OptionValidator
|
7
7
|
def server
|
8
|
-
invoke(Assets, :compile, [], { theme:
|
8
|
+
invoke(Assets, :compile, [], { theme: theme.identifier })
|
9
9
|
invoke(Fonts, :compile, [], {})
|
10
|
-
info("▸ starting server for theme '#{
|
10
|
+
info("▸ starting server for theme '#{theme.identifier}' on '127.0.0.1:#{options.port}'")
|
11
11
|
require 'maglove/server'
|
12
|
-
MagLove::Server.start(options.port,
|
12
|
+
MagLove::Server.start(options.port, theme.identifier, theme.templates)
|
13
13
|
end
|
14
14
|
|
15
15
|
desc "thumbnails", "Create page thumbnails"
|
@@ -17,17 +17,20 @@ module MagLove
|
|
17
17
|
def thumbnails
|
18
18
|
require "powersnap"
|
19
19
|
invoke(Fonts, :compile, [], {})
|
20
|
-
invoke(Assets, :compile, [], theme:
|
20
|
+
invoke(Assets, :compile, [], theme: theme.identifier)
|
21
21
|
|
22
22
|
info("▸ Generating Template Thumbnails")
|
23
|
-
output_dir =
|
24
|
-
|
25
|
-
powersnap
|
23
|
+
output_dir = theme.dist_dir.dir("templates")
|
24
|
+
urls = output_dir.children("*.html").map { |file| "file://#{file.absolute_path}" }
|
25
|
+
powersnap = Powersnap.new(urls)
|
26
|
+
response = powersnap.generate(dir: output_dir.to_s, width: 768, height: 1024, pattern: "{basename}.png", zoom: 1.0, page: false)
|
27
|
+
error!("Error generating thumbnails. Make sure npm module 'powersnap' is installed globally") if response["status"] != "success"
|
26
28
|
|
27
29
|
info("▸ Generating Block Thumbnails")
|
28
|
-
output_dir =
|
30
|
+
output_dir = theme.dist_dir.dir("blocks")
|
29
31
|
if output_dir.exists?
|
30
|
-
|
32
|
+
urls = output_dir.children("*.html").map { |file| "file://#{file.absolute_path}" }
|
33
|
+
powersnap = Powersnap.new(urls)
|
31
34
|
powersnap.generate(dir: output_dir.to_s, width: 512, height: 200, pattern: "{basename}.png", zoom: 1.0, page: true)
|
32
35
|
end
|
33
36
|
end
|
@@ -37,73 +40,75 @@ module MagLove
|
|
37
40
|
option :theme, type: :string, required: true, validator: OptionValidator
|
38
41
|
option :thumbnails, type: :boolean, default: false
|
39
42
|
def push
|
40
|
-
info("▸ Pushing theme '#{
|
43
|
+
info("▸ Pushing theme '#{theme.identifier}' to MagLoft")
|
41
44
|
|
42
45
|
# validate theme
|
43
|
-
|
44
|
-
error!("Theme '#{theme_identifier}' not found") unless theme_identifier
|
46
|
+
error!("Theme '#{theme.identifier}' not found") unless theme.identifier
|
45
47
|
begin
|
46
|
-
|
48
|
+
typeloft_theme = magloft_api.typeloft_themes.find_by_identifier(theme.identifier)
|
47
49
|
rescue MagLoft::ApiCaller::UnauthorizedError
|
48
50
|
error!("▸ You are not allowed to access the MagLoft API.")
|
49
51
|
end
|
50
|
-
if
|
51
|
-
info("▸ To create a new theme, run: maglove theme:create --theme '#{
|
52
|
-
error!("Theme '#{
|
52
|
+
if typeloft_theme.nil?
|
53
|
+
info("▸ To create a new theme, run: maglove theme:create --theme '#{theme.identifier}'")
|
54
|
+
error!("Theme '#{theme.identifier}' was not yet created.")
|
53
55
|
end
|
54
56
|
|
55
57
|
# invoke asset compilation
|
56
58
|
invoke(Fonts, :compile, [], {})
|
57
|
-
invoke(Assets, :compile, [], { theme:
|
58
|
-
invoke(Assets, :compress, [], { theme:
|
59
|
+
invoke(Assets, :compile, [], { theme: theme.identifier })
|
60
|
+
invoke(Assets, :compress, [], { theme: theme.identifier })
|
59
61
|
|
60
62
|
# update theme
|
61
63
|
info("▸ Synchronizing Metadata")
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
typeloft_theme.base_version = theme.base_version
|
65
|
+
typeloft_theme.name = theme.name
|
66
|
+
typeloft_theme.description = theme.description
|
67
|
+
typeloft_theme.widgets = theme.widgets
|
68
|
+
typeloft_theme.fonts = theme.fonts
|
69
|
+
typeloft_theme.save
|
68
70
|
|
69
71
|
# upload blocks
|
70
|
-
|
72
|
+
info("▸ Synchronizing Blocks")
|
73
|
+
theme_blocks = typeloft_theme.typeloft_blocks.all
|
71
74
|
theme_blocks_map = Hash[theme_blocks.map { |block| [block.identifier, block] }]
|
72
|
-
if
|
73
|
-
block_files =
|
75
|
+
if theme.src_dir.dir("blocks").exists?
|
76
|
+
block_files = theme.src_dir.dir("blocks").children("**/*.haml")
|
74
77
|
block_files.each do |block_file|
|
75
|
-
block_identifier = block_file.
|
78
|
+
block_identifier = block_file.basename
|
76
79
|
if (block = theme_blocks_map[block_identifier])
|
77
80
|
block.name = block_file.basename.titlecase
|
78
81
|
block.contents = block_file.read
|
82
|
+
block.contents.length
|
79
83
|
if block.changed?
|
80
84
|
info "▸ Updating Block '#{block_identifier}'"
|
81
85
|
block.save
|
82
86
|
end
|
83
87
|
else
|
84
88
|
info "▸ Creating Block '#{block_identifier}'"
|
85
|
-
|
89
|
+
typeloft_theme.typeloft_blocks.create(identifier: block_identifier, name: block_file.basename.titlecase, contents: block_file.read)
|
86
90
|
end
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
90
94
|
# upload images
|
91
95
|
info("▸ Synchronizing Images")
|
92
|
-
theme_images =
|
96
|
+
theme_images = typeloft_theme.typeloft_images.all
|
93
97
|
theme_images_map = Hash[theme_images.map { |image| [image.remote_file, image] }]
|
94
98
|
hydra = Typhoeus::Hydra.new
|
95
|
-
|
96
|
-
remote_file = "themes/#{
|
99
|
+
theme.dist_dir.children("images/**/*.{jpg,png,gif,svg}").each do |image_file|
|
100
|
+
remote_file = "themes/#{theme.identifier}/#{image_file.relative_path}"
|
97
101
|
if (existing_image = theme_images_map[remote_file])
|
98
|
-
|
102
|
+
image_file_md5 = Digest::MD5.hexdigest(image_file.read)
|
103
|
+
if image_file_md5 != existing_image.md5
|
99
104
|
info("▸ Updating Image '#{remote_file}'")
|
100
|
-
existing_image.md5 =
|
105
|
+
existing_image.md5 = image_file_md5
|
101
106
|
hydra.queue(existing_image.queue_upload(image_file.to_s) { debug("▸ Finished updating Image '#{remote_file}'") })
|
102
107
|
existing_image.save
|
103
108
|
end
|
104
109
|
else
|
105
110
|
info("▸ Creating Image '#{remote_file}'")
|
106
|
-
new_image =
|
111
|
+
new_image = typeloft_theme.typeloft_images.create(remote_file: remote_file, title: image_file.basename.titlecase, md5: image_file_md5)
|
107
112
|
hydra.queue(new_image.queue_upload(image_file.to_s) { info("▸ Finished creating Image '#{remote_file}'") })
|
108
113
|
end
|
109
114
|
end
|
@@ -111,17 +116,17 @@ module MagLove
|
|
111
116
|
|
112
117
|
# upload css/js
|
113
118
|
info("▸ Synchronizing JavaScript")
|
114
|
-
|
119
|
+
typeloft_theme.upload_javascript(theme.dist_dir.file("theme.js").to_s)
|
115
120
|
info("▸ Synchronizing Stylesheet")
|
116
|
-
|
121
|
+
typeloft_theme.upload_stylesheet(theme.dist_dir.file("theme.css").to_s)
|
117
122
|
|
118
123
|
# upload templates
|
119
124
|
info("▸ Synchronizing Templates")
|
120
|
-
theme_templates =
|
125
|
+
theme_templates = typeloft_theme.typeloft_templates.all
|
121
126
|
theme_templates_map = Hash[theme_templates.map { |template| [template.identifier, template] }]
|
122
|
-
templates =
|
127
|
+
templates = theme.templates
|
123
128
|
templates.each_with_index do |template_identifier, position|
|
124
|
-
template_file =
|
129
|
+
template_file = theme.src_dir.file("templates/#{template_identifier}.haml")
|
125
130
|
next unless !template_file.nil? and template_file.exists?
|
126
131
|
if (template = theme_templates_map[template_identifier])
|
127
132
|
template.title = template_identifier.titlecase
|
@@ -133,18 +138,18 @@ module MagLove
|
|
133
138
|
end
|
134
139
|
else
|
135
140
|
info "▸ Creating Template '#{template_identifier}'"
|
136
|
-
|
141
|
+
typeloft_theme.typeloft_templates.create(identifier: template_identifier, title: template_identifier.titlecase, contents: template_file.read, position: position)
|
137
142
|
end
|
138
143
|
end
|
139
144
|
|
140
145
|
# update thumbnails
|
141
146
|
if options.thumbnails
|
142
|
-
invoke(:thumbnails, [], { theme:
|
147
|
+
invoke(:thumbnails, [], { theme: theme.identifier })
|
143
148
|
hydra = Typhoeus::Hydra.new
|
144
149
|
|
145
150
|
info("▸ Synchronizing Template Thumbnails")
|
146
|
-
|
147
|
-
thumbnail_file =
|
151
|
+
typeloft_theme.typeloft_templates.all.each do |template|
|
152
|
+
thumbnail_file = theme.dist_dir.dir("templates").file("#{template.identifier}.png")
|
148
153
|
if thumbnail_file.exists?
|
149
154
|
info("~> Uploading Thumbnail for '#{template.identifier}'")
|
150
155
|
hydra.queue(template.queue_upload_thumbnail(thumbnail_file.to_s) { info("▸ Finished uploading Thumbnail for '#{template.identifier}'") })
|
@@ -152,8 +157,8 @@ module MagLove
|
|
152
157
|
end
|
153
158
|
|
154
159
|
info("▸ Synchronizing Block Thumbnails")
|
155
|
-
|
156
|
-
thumbnail_file =
|
160
|
+
typeloft_theme.typeloft_blocks.all.each do |block|
|
161
|
+
thumbnail_file = theme.dist_dir.dir("blocks").file("#{block.identifier}.png")
|
157
162
|
if thumbnail_file.exists?
|
158
163
|
info("~> Uploading Thumbnail for '#{block.identifier}'")
|
159
164
|
hydra.queue(block.queue_upload_thumbnail(thumbnail_file.to_s) { info("▸ Finished uploading Thumbnail for '#{block.identifier}'") })
|
@@ -169,13 +174,13 @@ module MagLove
|
|
169
174
|
option :token, type: :string, required: true
|
170
175
|
option :theme, type: :string, required: true, validator: OptionValidator
|
171
176
|
def create
|
172
|
-
info("▸ Creating new theme '#{
|
177
|
+
info("▸ Creating new theme '#{theme.identifier}'")
|
173
178
|
|
174
|
-
error!("Missing yaml config 'name'") unless
|
175
|
-
error!("Missing yaml config 'base_version'") unless
|
176
|
-
|
177
|
-
error!("This theme already exists") unless
|
178
|
-
magloft_api.typeloft_themes.create(identifier:
|
179
|
+
error!("Missing yaml config 'name'") unless theme.name
|
180
|
+
error!("Missing yaml config 'base_version'") unless theme.base_version
|
181
|
+
typeloft_theme = magloft_api.typeloft_themes.find_by_identifier(theme.identifier)
|
182
|
+
error!("This theme already exists") unless typeloft_theme.nil?
|
183
|
+
magloft_api.typeloft_themes.create(identifier: theme.identifier, name: theme.name, description: theme.description, base_version: theme.base_version)
|
179
184
|
info("▸ Theme successfully created!")
|
180
185
|
end
|
181
186
|
|
@@ -183,10 +188,10 @@ module MagLove
|
|
183
188
|
option :token, type: :string, required: true
|
184
189
|
option :theme, type: :string, required: true
|
185
190
|
def delete
|
186
|
-
info("▸ Deleting theme '#{
|
187
|
-
|
188
|
-
error!("Could not find a theme with identifier '#{
|
189
|
-
|
191
|
+
info("▸ Deleting theme '#{theme.identifier}'")
|
192
|
+
typeloft_theme = magloft_api.typeloft_themes.find_by_identifier(theme.identifier)
|
193
|
+
error!("Could not find a theme with identifier '#{theme.identifier}'") if typeloft_theme.nil?
|
194
|
+
typeloft_theme.destroy
|
190
195
|
info("▸ Theme successfully deleted!")
|
191
196
|
end
|
192
197
|
|
@@ -194,8 +199,8 @@ module MagLove
|
|
194
199
|
option :token, type: :string, required: true
|
195
200
|
def list
|
196
201
|
info("▸ Listing themes")
|
197
|
-
magloft_api.typeloft_themes.all.each do |
|
198
|
-
info("~> #{
|
202
|
+
magloft_api.typeloft_themes.all.each do |typeloft_theme|
|
203
|
+
info("~> #{typeloft_theme.identifier} (NAME: #{typeloft_theme.name}, ACTIVE: #{typeloft_theme.active ? 'YES' : 'NO'})")
|
199
204
|
end
|
200
205
|
end
|
201
206
|
end
|