maglove 2.0.4 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/{vendor → assets}/autoprefixer.js +0 -0
  3. data/{data/maglove → assets}/export.haml +0 -0
  4. data/{data/maglove → assets}/hpub/index.css +0 -0
  5. data/{data/maglove → assets}/hpub/index.haml +0 -0
  6. data/{data/maglove → assets}/hpub/page.haml +0 -0
  7. data/{data/maglove → assets}/index.haml +0 -0
  8. data/{data/maglove → assets}/maglove.css +0 -0
  9. data/{data/maglove → assets}/maglove.haml +0 -0
  10. data/{data/maglove → assets}/maglove.js +1 -1
  11. data/{data/maglove → assets}/scaffold/base/base.coffee +0 -0
  12. data/{data/maglove → assets}/scaffold/base/base.less +0 -0
  13. data/{data/maglove → assets}/scaffold/base/images/base/loading-bars.svg +0 -0
  14. data/{data/maglove → assets}/scaffold/base/less/base/animations.less +0 -0
  15. data/{data/maglove → assets}/scaffold/base/less/base/blockquotes.less +0 -0
  16. data/{data/maglove → assets}/scaffold/base/less/base/buttons.less +0 -0
  17. data/{data/maglove → assets}/scaffold/base/less/base/code.less +0 -0
  18. data/{data/maglove → assets}/scaffold/base/less/base/forms.less +0 -0
  19. data/{data/maglove → assets}/scaffold/base/less/base/global.less +0 -0
  20. data/{data/maglove → assets}/scaffold/base/less/base/grid-minimal.less +0 -0
  21. data/{data/maglove → assets}/scaffold/base/less/base/grid-non-responsive.less +0 -0
  22. data/{data/maglove → assets}/scaffold/base/less/base/grid.less +0 -0
  23. data/{data/maglove → assets}/scaffold/base/less/base/helpers.less +0 -0
  24. data/{data/maglove → assets}/scaffold/base/less/base/images.less +0 -0
  25. data/{data/maglove → assets}/scaffold/base/less/base/lists.less +0 -0
  26. data/{data/maglove → assets}/scaffold/base/less/base/mixins.less +0 -0
  27. data/{data/maglove → assets}/scaffold/base/less/base/print.less +0 -0
  28. data/{data/maglove → assets}/scaffold/base/less/base/resets.less +0 -0
  29. data/{data/maglove → assets}/scaffold/base/less/base/tables.less +0 -0
  30. data/{data/maglove → assets}/scaffold/base/less/core/alignments.less +0 -0
  31. data/{data/maglove → assets}/scaffold/base/less/core/cleanup.less +0 -0
  32. data/{data/maglove → assets}/scaffold/base/less/core/editor.less +0 -0
  33. data/{data/maglove → assets}/scaffold/base/less/core/typography.less +0 -0
  34. data/{data/maglove → assets}/scaffold/base/less/vendor/flex-video.less +0 -0
  35. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome.less +0 -0
  36. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/animated.less +0 -0
  37. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/bordered-pulled.less +0 -0
  38. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/core.less +0 -0
  39. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/fixed-width.less +0 -0
  40. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/font-awesome.less +0 -0
  41. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/icons.less +0 -0
  42. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/larger.less +0 -0
  43. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/list.less +0 -0
  44. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/mixins.less +0 -0
  45. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/rotated-flipped.less +0 -0
  46. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/stacked.less +0 -0
  47. data/{data/maglove → assets}/scaffold/base/less/vendor/font-awesome/variables.less +0 -0
  48. data/{data/maglove → assets}/scaffold/base/less/vendor/image-loader.less +0 -0
  49. data/{data/maglove → assets}/scaffold/base/less/vendor/magnific-popup.less +0 -0
  50. data/{data/maglove → assets}/scaffold/base/less/widgets/banner.less +0 -0
  51. data/{data/maglove → assets}/scaffold/base/less/widgets/button.less +0 -0
  52. data/{data/maglove → assets}/scaffold/base/less/widgets/callout.less +0 -0
  53. data/{data/maglove → assets}/scaffold/base/less/widgets/columns.less +0 -0
  54. data/{data/maglove → assets}/scaffold/base/less/widgets/container.less +0 -0
  55. data/{data/maglove → assets}/scaffold/base/less/widgets/feedback.less +0 -0
  56. data/{data/maglove → assets}/scaffold/base/less/widgets/heading.less +0 -0
  57. data/{data/maglove → assets}/scaffold/base/less/widgets/horizontal_rule.less +0 -0
  58. data/{data/maglove → assets}/scaffold/base/less/widgets/image.less +0 -0
  59. data/{data/maglove → assets}/scaffold/base/less/widgets/paragraph.less +0 -0
  60. data/{data/maglove → assets}/scaffold/base/variables.less +0 -0
  61. data/{data/maglove → assets}/scaffold/base/vendor/jquery.js +0 -0
  62. data/{data/maglove → assets}/scaffold/theme/images/logo.png +0 -0
  63. data/{data/maglove → assets}/scaffold/theme/images/pattern/symphony.png +0 -0
  64. data/{data/maglove → assets}/scaffold/theme/less/base/variables.less +0 -0
  65. data/{data/maglove → assets}/scaffold/theme/templates/article-01.haml +3 -3
  66. data/{data/maglove → assets}/scaffold/theme/templates/cover.haml +0 -0
  67. data/{data/maglove → assets}/scaffold/theme/templates/toc.haml +1 -1
  68. data/{data/maglove → assets}/scaffold/theme/templates/toc.yml +0 -0
  69. data/{data/maglove → assets}/scaffold/theme/theme.coffee +0 -0
  70. data/{data/maglove → assets}/scaffold/theme/theme.less +0 -0
  71. data/{data/maglove → assets}/thumbnail.haml +0 -0
  72. data/{data/maglove → assets}/thumbnail.js +0 -0
  73. data/bin/maglove +0 -6
  74. data/lib/magloft/api_caller.rb +12 -12
  75. data/lib/magloft/remote_resource.rb +17 -17
  76. data/lib/maglove.rb +19 -19
  77. data/lib/maglove/asset/theme.rb +7 -6
  78. data/lib/maglove/commands/assets.rb +61 -44
  79. data/lib/maglove/commands/base.rb +5 -1
  80. data/lib/maglove/commands/fonts.rb +9 -6
  81. data/lib/maglove/commands/main.rb +3 -1
  82. data/lib/maglove/commands/theme.rb +63 -58
  83. data/lib/maglove/middleware/live_reload.rb +19 -11
  84. data/lib/maglove/server.rb +18 -8
  85. data/lib/maglove/theme.rb +27 -0
  86. data/lib/maglove/tilt/coffee_template.rb +1 -1
  87. data/lib/maglove/tilt/haml_template.rb +2 -3
  88. data/lib/maglove/tilt/js_template.rb +1 -2
  89. data/lib/maglove/tilt/scss_template.rb +3 -9
  90. data/lib/maglove/tilt/yaml_template.rb +2 -3
  91. data/lib/maglove/version.rb +1 -1
  92. data/lib/powersnap.rb +1 -3
  93. metadata +164 -155
  94. data/.gitignore +0 -9
  95. data/.rubocop.yml +0 -157
  96. data/Gemfile +0 -3
  97. data/Gemfile.lock +0 -206
  98. data/README.md +0 -26
  99. data/lib/block_resolver.rb +0 -6
  100. data/lib/maglove/application.rb +0 -58
  101. data/lib/maglove/phantom_script.rb +0 -44
  102. data/lib/maglove/workspace.rb +0 -41
  103. data/lib/workspace.rb +0 -11
  104. data/lib/workspace/workspace_dir.rb +0 -98
  105. data/lib/workspace/workspace_dir/archive.rb +0 -18
  106. data/lib/workspace/workspace_file.rb +0 -127
  107. data/lib/workspace/workspace_file/archive.rb +0 -45
  108. data/lib/workspace/workspace_file/media.rb +0 -19
  109. data/lib/workspace/workspace_file/net.rb +0 -18
  110. data/lib/workspace/workspace_file/parse.rb +0 -21
  111. 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
- theme_dir(root: "dist").reset!
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
- workspace_dir("src/base/#{theme_config(:base_version)}").files("images/**/*.{jpg,png,gif,svg}").each do |file|
27
+ theme.base_dir.children("images/**/*.{jpg,png,gif,svg}").each do |file|
28
28
  debug("~> Copying #{file}")
29
- file.asset(theme: options.theme, base: true).write!
29
+ MagLove::Asset::Theme.new(file.path, { base: true }).write!
30
30
  end
31
- theme_dir.files("images/**/*.{jpg,png,gif,svg}").each do |file|
31
+ theme.src_dir.children("images/**/*.{jpg,png,gif,svg}").each do |file|
32
32
  debug("~> Copying #{file}")
33
- file.asset.write!
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
- theme_dir.files("videos/**/*.{mp4,webm,ogg}").each do |file|
40
+ theme.src_dir.children("videos/**/*.{mp4,webm,ogg}").each do |file|
41
41
  debug("~> Copying #{file}")
42
- file.asset(theme: options.theme).write!
42
+ MagLove::Asset::Theme.new(file.path, { base: false }).write!
43
43
  end
44
44
  end
45
-
46
- desc "imageoptim", "Optimize images"
45
+
46
+ desc "optimizeimages", "Optimize images"
47
47
  option :percent, type: :numeric, required: true, default: 25
48
- def imageoptim
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
- theme_dir.files("images/**/*.{jpg,png,gif}").each do |file|
53
- if optimizer.optimizable?(file.to_s)
54
- new_path = optimizer.optimize_image(file.to_s)
55
- if !new_path.nil?
56
- new_file = WorkspaceFile.new("/", new_path.to_s)
57
- improvement = (file.size.to_f / new_file.size - 1) * 100
58
- if improvement >= options.percent
59
- info("~> #{file} optimized #{improvement.to_i}% (#{file.size/1000}kb to #{new_file.size/1000}kb)")
60
- new_file.move(file)
61
- else
62
- debug("~> #{file} (#{improvement.to_i}% < #{options.percent}%)")
63
- end
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
- theme_dir.file("theme.coffee").asset.write!
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
- theme_dir.files("theme.{scss,less}").first.asset(asset_uri: ".").write!
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
- theme_dir.file("theme.yml").asset.write!
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
- theme_dir(root: "dist").file("theme.js").minify!
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
- theme_dir(root: "dist").file("theme.css").minify!
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
- asset_uri = "file://#{workspace_dir('dist').absolute_path}"
102
- theme_config(:templates).each do |template|
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 = theme_dir.file("templates/#{template}.haml")
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.asset(asset_uri: asset_uri).contents
107
- html_contents = gem_dir.file("export.haml").read_hamloft(theme: options.theme, contents: contents, asset_uri: asset_uri)
108
- theme_dir(root: "dist").file("templates/#{template}.html").write(html_contents)
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 theme_dir.dir("blocks").exists?
116
- asset_uri = "file://#{workspace_dir('dist').absolute_path}"
117
- theme_dir.dir("blocks").files("**/*.haml").each do |block_file|
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.asset(asset_uri: asset_uri).contents
120
- html_contents = gem_dir.file("export.haml").read_hamloft(theme: options.theme, contents: contents, asset_uri: asset_uri)
121
- theme_dir(root: "dist").file("blocks/#{block_file.basename}.html").write(html_contents)
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
- debug("▸ compiling fonts:")
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
- debug("▸ all font styles created")
44
- if options.sync
45
- # @TODO: Submit to cloud server
46
- debug("▸ all fonts synchronized")
47
- end
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
- workspace_dir("src/themes").each_dir do |dir|
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: options.theme })
8
+ invoke(Assets, :compile, [], { theme: theme.identifier })
9
9
  invoke(Fonts, :compile, [], {})
10
- info("▸ starting server for theme '#{options.theme}' on '127.0.0.1:#{options.port}'")
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, options.theme, theme_config(:templates))
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: options.theme)
20
+ invoke(Assets, :compile, [], theme: theme.identifier)
21
21
 
22
22
  info("▸ Generating Template Thumbnails")
23
- output_dir = theme_dir(root: "dist").chdir("templates")
24
- powersnap = Powersnap.new(output_dir.files("*.html").map(&:url))
25
- powersnap.generate(dir: output_dir.to_s, width: 768, height: 1024, pattern: "{basename}.png", zoom: 1.0, page: false)
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 = theme_dir(root: "dist").chdir("blocks")
30
+ output_dir = theme.dist_dir.dir("blocks")
29
31
  if output_dir.exists?
30
- powersnap = Powersnap.new(output_dir.files("*.html").map(&:url))
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 '#{options.theme}' to MagLoft")
43
+ info("▸ Pushing theme '#{theme.identifier}' to MagLoft")
41
44
 
42
45
  # validate theme
43
- theme_identifier = theme_config(:identifier)
44
- error!("Theme '#{theme_identifier}' not found") unless theme_identifier
46
+ error!("Theme '#{theme.identifier}' not found") unless theme.identifier
45
47
  begin
46
- theme = magloft_api.typeloft_themes.find_by_identifier(theme_identifier)
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 theme.nil?
51
- info("▸ To create a new theme, run: maglove theme:create --theme '#{theme_identifier}'")
52
- error!("Theme '#{theme_identifier}' was not yet created.")
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: options.theme })
58
- invoke(Assets, :compress, [], { theme: options.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
- theme.base_version = theme_config(:base_version)
63
- theme.name = theme_config(:name)
64
- theme.description = theme_config(:description)
65
- theme.widgets = theme_config(:widgets)
66
- theme.fonts = theme_config(:fonts)
67
- theme.save
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
- theme_blocks = theme.typeloft_blocks.all
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 theme_dir.chdir("blocks").exists?
73
- block_files = theme_dir.chdir("blocks").files("**/*.haml")
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.slug
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
- theme.typeloft_blocks.create(identifier: block_identifier, name: block_file.basename.titlecase, contents: block_file.read)
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 = theme.typeloft_images.all
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
- theme_dir(root: "dist").files("images/**/*.{jpg,png,gif,svg}").each do |image_file|
96
- remote_file = "themes/#{options.theme}/#{image_file.relative_path}"
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
- if image_file.md5 != existing_image.md5
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 = image_file.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 = theme.typeloft_images.create(remote_file: remote_file, title: image_file.basename.titlecase, md5: image_file.md5)
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
- theme.upload_javascript(theme_dir(root: "dist").file("theme.js").to_s)
119
+ typeloft_theme.upload_javascript(theme.dist_dir.file("theme.js").to_s)
115
120
  info("▸ Synchronizing Stylesheet")
116
- theme.upload_stylesheet(theme_dir(root: "dist").file("theme.css").to_s)
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 = theme.typeloft_templates.all
125
+ theme_templates = typeloft_theme.typeloft_templates.all
121
126
  theme_templates_map = Hash[theme_templates.map { |template| [template.identifier, template] }]
122
- templates = theme_config(:templates)
127
+ templates = theme.templates
123
128
  templates.each_with_index do |template_identifier, position|
124
- template_file = theme_dir.file("templates/#{template_identifier}.haml")
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
- theme.typeloft_templates.create(identifier: template_identifier, title: template_identifier.titlecase, contents: template_file.read, position: position)
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: options.theme })
147
+ invoke(:thumbnails, [], { theme: theme.identifier })
143
148
  hydra = Typhoeus::Hydra.new
144
149
 
145
150
  info("▸ Synchronizing Template Thumbnails")
146
- theme.typeloft_templates.all.each do |template|
147
- thumbnail_file = theme_dir(root: "dist").dir("templates").file("#{template.identifier}.png")
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
- theme.typeloft_blocks.all.each do |block|
156
- thumbnail_file = theme_dir(root: "dist").dir("blocks").file("#{block.identifier}.png")
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 '#{options.theme}'")
177
+ info("▸ Creating new theme '#{theme.identifier}'")
173
178
 
174
- error!("Missing yaml config 'name'") unless theme_config(:name)
175
- error!("Missing yaml config 'base_version'") unless theme_config(:base_version)
176
- theme = magloft_api.typeloft_themes.find_by_identifier(options.theme)
177
- error!("This theme already exists") unless theme.nil?
178
- magloft_api.typeloft_themes.create(identifier: options.theme, name: theme_config(:name), description: theme_config(:description), base_version: theme_config(:base_version))
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 '#{options.theme}'")
187
- theme = magloft_api.typeloft_themes.find_by_identifier(options.theme)
188
- error!("Could not find a theme with identifier '#{options.theme}'") if theme.nil?
189
- theme.destroy
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 |theme|
198
- info("~> #{theme.identifier} (NAME: #{theme.name}, ACTIVE: #{theme.active ? 'YES' : 'NO'})")
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