maglove 0.8.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +157 -0
- data/Gemfile.lock +59 -49
- data/bin/maglove +13 -13
- data/data/maglove/export.haml +11 -0
- data/data/maglove/index.haml +17 -0
- data/data/maglove/maglove.css +62 -0
- data/data/maglove/maglove.haml +18 -0
- data/data/maglove/maglove.js +68 -0
- data/lib/block_resolver.rb +6 -0
- data/lib/ext/thor/option.rb +43 -0
- data/lib/magloft/api.rb +39 -0
- data/lib/magloft/api_caller.rb +67 -0
- data/lib/magloft/remote_collection.rb +50 -0
- data/lib/magloft/remote_resource.rb +124 -0
- data/lib/magloft/transformable.rb +11 -0
- data/lib/magloft/typeloft_block.rb +18 -0
- data/lib/magloft/typeloft_image.rb +18 -0
- data/lib/magloft/typeloft_template.rb +18 -0
- data/lib/magloft/typeloft_theme.rb +41 -0
- data/lib/magloft.rb +3 -0
- data/lib/maglove/application.rb +10 -12
- data/lib/maglove/asset/theme.rb +37 -32
- data/lib/maglove/commands/assets.rb +85 -0
- data/lib/maglove/commands/base.rb +55 -0
- data/lib/maglove/commands/fonts.rb +69 -0
- data/lib/maglove/commands/main.rb +24 -0
- data/lib/maglove/commands/theme.rb +197 -0
- data/lib/maglove/helper/log_helper.rb +3 -18
- data/lib/maglove/middleware/live_reload.rb +97 -0
- data/lib/maglove/phantom_script.rb +9 -10
- data/lib/maglove/server.rb +46 -78
- data/lib/maglove/tilt/coffee_template.rb +7 -6
- data/lib/maglove/tilt/haml_template.rb +4 -4
- data/lib/maglove/tilt/js_template.rb +8 -8
- data/lib/maglove/tilt/less_template.rb +5 -4
- data/lib/maglove/tilt/scss_template.rb +17 -11
- data/lib/maglove/tilt/yaml_template.rb +3 -2
- data/lib/maglove/version.rb +1 -1
- data/lib/maglove/workspace.rb +41 -0
- data/lib/maglove.rb +38 -49
- data/lib/powersnap.rb +24 -0
- data/lib/workspace/workspace_dir/archive.rb +18 -0
- data/lib/workspace/workspace_dir.rb +98 -0
- data/lib/workspace/workspace_file/archive.rb +45 -0
- data/lib/workspace/workspace_file/media.rb +19 -0
- data/lib/workspace/workspace_file/net.rb +18 -0
- data/lib/workspace/workspace_file/parse.rb +21 -0
- data/lib/workspace/workspace_file.rb +99 -0
- data/lib/workspace.rb +11 -0
- data/maglove.gemspec +12 -12
- metadata +100 -86
- data/data/maglove/dump.haml +0 -58
- data/data/maglove/sdk.haml +0 -27
- data/lib/ext/commander/command.rb +0 -32
- data/lib/ext/commander/methods.rb +0 -8
- data/lib/maglove/asset/base_theme.rb +0 -17
- data/lib/maglove/command/compile.rb +0 -44
- data/lib/maglove/command/compress.rb +0 -28
- data/lib/maglove/command/copy.rb +0 -35
- data/lib/maglove/command/core.rb +0 -23
- data/lib/maglove/command/font.rb +0 -80
- data/lib/maglove/command/server.rb +0 -16
- data/lib/maglove/command/sync.rb +0 -17
- data/lib/maglove/command/theme.rb +0 -175
- data/lib/maglove/command/util.rb +0 -45
- data/lib/maglove/helper/asset_helper.rb +0 -24
- data/lib/maglove/helper/command_helper.rb +0 -67
- data/lib/maglove/helper/theme_helper.rb +0 -105
- data/lib/maglove/server/hpub.rb +0 -185
- data/lib/maglove/template/tumblr.rb +0 -81
- data/lib/maglove/tilt/twig_template.rb +0 -49
@@ -4,24 +4,22 @@ module MagLove
|
|
4
4
|
self.default_mime_type = 'application/javascript'
|
5
5
|
|
6
6
|
def prepare
|
7
|
-
|
8
7
|
end
|
9
8
|
|
10
9
|
def evaluate(scope, locals, &block)
|
11
|
-
|
12
10
|
# handle includes
|
13
|
-
@data = @data.gsub(
|
11
|
+
@data = @data.gsub(%r{^//=\srequire\s(.+)$}) do |match|
|
14
12
|
path = Regexp.last_match[1]
|
15
13
|
include_path = File.absolute_path(path, File.dirname(file))
|
16
|
-
|
14
|
+
|
17
15
|
# check if base path exists
|
18
|
-
|
16
|
+
unless File.exist?(include_path)
|
19
17
|
include_path = File.absolute_path(path, locals[:base_path])
|
20
18
|
end
|
21
|
-
|
22
|
-
if File.
|
19
|
+
|
20
|
+
if File.exist?(include_path)
|
23
21
|
include_template = ::Tilt.new(include_path)
|
24
|
-
|
22
|
+
include_template.render(Object.new, locals)
|
25
23
|
else
|
26
24
|
raise "Path not found: #{include_path}"
|
27
25
|
end
|
@@ -36,3 +34,5 @@ module MagLove
|
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
37
|
+
|
38
|
+
Tilt.mappings["js"] = [MagLove::Tilt::JsTemplate]
|
@@ -4,15 +4,16 @@ module MagLove
|
|
4
4
|
self.default_mime_type = 'theme/html'
|
5
5
|
|
6
6
|
def prepare
|
7
|
-
@parser
|
7
|
+
@parser = ::Less::Parser.new(options.merge(filename: eval_file, line: line, relativeUrls: false))
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def evaluate(scope, locals, &block)
|
11
|
-
prepared_data = "@base: \"#{locals[:base_path].sub(
|
11
|
+
prepared_data = "@base: \"#{locals[:base_path].sub('src/', '../../')}\";\n#{data}"
|
12
12
|
@engine = @parser.parse(prepared_data)
|
13
13
|
@output ||= @engine.to_css(options)
|
14
14
|
end
|
15
|
-
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
18
|
+
|
19
|
+
Tilt.mappings["less"] = [MagLove::Tilt::LessTemplate]
|
@@ -1,10 +1,13 @@
|
|
1
|
-
module Sass::Script::Functions
|
1
|
+
module Sass::Script::Functions
|
2
2
|
def asset(url)
|
3
3
|
assert_type url, :String
|
4
|
-
Sass::Script::Value::String.new("url(\"#{
|
4
|
+
Sass::Script::Value::String.new("url(\"#{asset_uri}/#{url.value}\")")
|
5
5
|
end
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
def asset_uri
|
8
|
+
options[:locals][:asset_uri] || Hamloft.asset_uri
|
9
|
+
end
|
10
|
+
|
8
11
|
def asset_data(url)
|
9
12
|
assert_type url, :String
|
10
13
|
theme = options[:locals][:theme]
|
@@ -23,20 +26,23 @@ module MagLove
|
|
23
26
|
module Tilt
|
24
27
|
class ScssTemplate < ::Tilt::SassTemplate
|
25
28
|
self.default_mime_type = 'text/css'
|
26
|
-
|
29
|
+
|
27
30
|
def prepare
|
28
31
|
end
|
29
32
|
|
30
33
|
def evaluate(scope, locals, &block)
|
31
|
-
prepared_data = "@base: \"#{locals[:base_path].sub(
|
32
|
-
engine = Sass::Engine.new(prepared_data, sass_options.merge({locals: locals}))
|
34
|
+
prepared_data = "@base: \"#{locals[:base_path].sub('src/', '../../')}\";\n#{data}"
|
35
|
+
engine = Sass::Engine.new(prepared_data, sass_options.merge({ locals: locals }))
|
33
36
|
@output ||= engine.render
|
34
37
|
end
|
35
|
-
|
38
|
+
|
36
39
|
private
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
|
41
|
+
def sass_options
|
42
|
+
options.merge(filename: eval_file, line: line, syntax: :scss)
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
47
|
+
|
48
|
+
Tilt.mappings["scss"] = [MagLove::Tilt::ScssTemplate]
|
@@ -2,9 +2,8 @@ module MagLove
|
|
2
2
|
module Tilt
|
3
3
|
class YamlTemplate < ::Tilt::Template
|
4
4
|
self.default_mime_type = 'application/json'
|
5
|
-
|
5
|
+
|
6
6
|
def prepare
|
7
|
-
|
8
7
|
end
|
9
8
|
|
10
9
|
def evaluate(scope, locals, &block)
|
@@ -17,3 +16,5 @@ module MagLove
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
19
|
+
|
20
|
+
Tilt.mappings["yml"] = [MagLove::Tilt::YamlTemplate]
|
data/lib/maglove/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Workspace
|
2
|
+
def theme_dir(root: "src", theme: options[:theme])
|
3
|
+
workspace_dir("#{root}/themes/#{theme}")
|
4
|
+
end
|
5
|
+
|
6
|
+
def theme_file(path, root: "src", theme: options[:theme])
|
7
|
+
workspace_file("#{root}/themes/#{theme}", path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def theme_base_file(path, theme: options[:theme])
|
11
|
+
theme_base_dir(theme: theme).file(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def theme_base_dir(theme: options[:theme])
|
15
|
+
base_version = theme_config(:base_version, theme: theme)
|
16
|
+
workspace_dir("src/base/#{base_version}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def gem_dir
|
20
|
+
workspace_dir(Gem.datadir("maglove"))
|
21
|
+
end
|
22
|
+
|
23
|
+
def theme_config(key = nil, theme: options[:theme])
|
24
|
+
Maglove.theme_config(key, theme)
|
25
|
+
end
|
26
|
+
|
27
|
+
class WorkspaceFile
|
28
|
+
def asset(theme: workspace_theme, base: false, asset_uri: ".")
|
29
|
+
MagLove::Asset::Theme.new(path, { theme: theme, base: base, asset_uri: asset_uri })
|
30
|
+
end
|
31
|
+
|
32
|
+
def workspace_theme
|
33
|
+
match = self.workspace.match(%r{/themes/([^/]+)})
|
34
|
+
match ? match[1] : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_hamloft(options = {})
|
38
|
+
Hamloft.render(read, options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/maglove.rb
CHANGED
@@ -1,51 +1,40 @@
|
|
1
|
-
require
|
2
|
-
require "
|
1
|
+
require 'magloft'
|
2
|
+
require "maglove/workspace"
|
3
|
+
require "maglove/widgets"
|
4
|
+
require "maglove/commands/base"
|
5
|
+
require "maglove/commands/fonts"
|
6
|
+
require "maglove/commands/theme"
|
7
|
+
require "maglove/commands/assets"
|
8
|
+
require "maglove/commands/main"
|
9
|
+
require "block_resolver"
|
3
10
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
require "image_optim"
|
18
|
-
require "zlib"
|
19
|
-
require 'zip'
|
20
|
-
require "archive/tar/minitar"
|
11
|
+
module Maglove
|
12
|
+
def self.theme_config(key = nil, theme)
|
13
|
+
@theme_config ||= {}
|
14
|
+
unless @theme_config[theme]
|
15
|
+
config_file = Workspace::WorkspaceFile.new("src/themes/#{theme}", "theme.yml")
|
16
|
+
@theme_config[theme] = config_file.read_yaml
|
17
|
+
end
|
18
|
+
if key.nil?
|
19
|
+
@theme_config[theme]
|
20
|
+
else
|
21
|
+
@theme_config[theme][key.to_s]
|
22
|
+
end
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
require "maglove/command/compile"
|
39
|
-
require "maglove/command/compress"
|
40
|
-
require "maglove/command/copy"
|
41
|
-
require "maglove/command/util"
|
42
|
-
require "maglove/command/font"
|
43
|
-
require "maglove/command/sync"
|
44
|
-
require "maglove/command/server"
|
45
|
-
require "maglove/phantom_script"
|
46
|
-
require "maglove/application"
|
47
|
-
require "maglove/asset/theme"
|
48
|
-
require "maglove/asset/base_theme"
|
49
|
-
require "maglove/server/hpub"
|
50
|
-
require "maglove/server"
|
51
|
-
require "maglove/template/tumblr"
|
25
|
+
def self.logger
|
26
|
+
if @logger.nil?
|
27
|
+
Logging.color_scheme("bright",
|
28
|
+
levels: { debug: :blue, info: :green, warn: :yellow, error: :red, fatal: [:white, :on_red] },
|
29
|
+
date: :blue,
|
30
|
+
mdc: :cyan,
|
31
|
+
logger: :cyan,
|
32
|
+
message: :black)
|
33
|
+
Logging.appenders.stdout("stdout", layout: Logging.layouts.pattern(pattern: '[%d] %-5l %-18X{full_command} %x %m\n', color_scheme: 'bright'))
|
34
|
+
@logger = Logging::Logger.new(self.class.name)
|
35
|
+
@logger.level = :debug
|
36
|
+
@logger.add_appenders('stdout')
|
37
|
+
end
|
38
|
+
@logger
|
39
|
+
end
|
40
|
+
end
|
data/lib/powersnap.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class Powersnap
|
2
|
+
attr_accessor :urls, :prefix
|
3
|
+
|
4
|
+
def initialize(urls, prefix: nil)
|
5
|
+
@urls = urls.map { |url| URI.encode(url) }
|
6
|
+
@prefix = prefix
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(dir: ".", width: 768, height: 1024, pattern: "image-{index}.png", zoom: 1.0, page: false, quality: 100, css: nil)
|
10
|
+
extension = File.extname(pattern)
|
11
|
+
if extension == ".jpg"
|
12
|
+
format = "jpeg"
|
13
|
+
elsif extension == ".png"
|
14
|
+
format = "png"
|
15
|
+
else
|
16
|
+
raise "Invalid file extension: #{extension}"
|
17
|
+
end
|
18
|
+
cmd = "#{@prefix} powersnap -j -d \"#{dir}\" -t \"#{format}\" -q #{quality} -z #{zoom} #{page ? '--page' : ''} -w #{width.to_i} -h #{height.to_i} #{(css and "-c #{css}")} -f \"#{pattern}\" #{@urls.join(' ')}"
|
19
|
+
json_response = `#{cmd}`
|
20
|
+
|
21
|
+
response = JSON.parse(json_response)
|
22
|
+
return response["stats"] == "success"
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Workspace
|
2
|
+
class WorkspaceDir
|
3
|
+
module Archive
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def compress_zip(target_file)
|
7
|
+
target_file.delete!
|
8
|
+
require "zip"
|
9
|
+
Zip::File.open(target_file.to_s, 'w') do |zipfile|
|
10
|
+
Dir["#{self}/**/**"].each do |file|
|
11
|
+
zipfile.add(file.sub("#{self}/", ''), file)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'workspace/workspace_dir/archive'
|
2
|
+
module Workspace
|
3
|
+
class WorkspaceDir
|
4
|
+
include Workspace::WorkspaceDir::Archive
|
5
|
+
|
6
|
+
attr_accessor :workspace, :path
|
7
|
+
|
8
|
+
def initialize(workspace, path = "")
|
9
|
+
@workspace = workspace
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
File.join(@workspace, @path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
File.basename(to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
FileUtils.mkdir_p(to_s)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def exists?
|
27
|
+
File.directory?(to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def copy(target_dir)
|
31
|
+
target_dir.parent_dir.create unless target_dir.parent_dir.exists?
|
32
|
+
FileUtils.cp_r(to_s, target_dir.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete!
|
36
|
+
FileUtils.rm_rf(to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset!
|
40
|
+
delete!
|
41
|
+
create
|
42
|
+
end
|
43
|
+
|
44
|
+
def file(file_path)
|
45
|
+
WorkspaceFile.new(@workspace, File.join(@path, file_path))
|
46
|
+
end
|
47
|
+
|
48
|
+
def dir(dir_path)
|
49
|
+
self.class.new(@workspace, File.join(@path, dir_path))
|
50
|
+
end
|
51
|
+
|
52
|
+
def root_dir
|
53
|
+
self.class.new(@workspace, "")
|
54
|
+
end
|
55
|
+
|
56
|
+
def chdir(target_dir = nil)
|
57
|
+
if target_dir.nil?
|
58
|
+
self.class.new(to_s, "")
|
59
|
+
else
|
60
|
+
self.class.new(dir(target_dir).to_s, "")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def parent_dir
|
65
|
+
root_dir.dir(File.expand_path("..", @path))
|
66
|
+
end
|
67
|
+
|
68
|
+
def children
|
69
|
+
entries = []
|
70
|
+
Dir.chdir(to_s) do
|
71
|
+
Dir["*"].each do |path|
|
72
|
+
entries.push(dir(path))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
entries
|
76
|
+
end
|
77
|
+
|
78
|
+
def files(glob = "*")
|
79
|
+
entries = []
|
80
|
+
Dir.chdir(to_s) do
|
81
|
+
Dir[glob].each do |path|
|
82
|
+
entries.push(file(path))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
entries
|
86
|
+
end
|
87
|
+
|
88
|
+
def each_dir(&block)
|
89
|
+
children.each do |subdir|
|
90
|
+
yield(subdir)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def absolute_path
|
95
|
+
File.absolute_path(to_s)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Workspace
|
2
|
+
class WorkspaceFile
|
3
|
+
module Archive
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def extract(target_dir)
|
7
|
+
target_dir.create
|
8
|
+
if extension == "zip"
|
9
|
+
extract_zip(target_dir)
|
10
|
+
elsif extension == "gz"
|
11
|
+
extract_gz(target_dir)
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def extract_zip(target_dir)
|
19
|
+
require "zip"
|
20
|
+
Zip::File.open(to_s) do |archive|
|
21
|
+
archive.each do |entry|
|
22
|
+
entry.extract(File.join(target_dir.to_s, entry.name))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def extract_gz(target_dir)
|
28
|
+
require 'rubygems/package'
|
29
|
+
workspace_dir = target_dir.root_dir
|
30
|
+
archive = Gem::Package::TarReader.new(Zlib::GzipReader.open(to_s))
|
31
|
+
archive.rewind
|
32
|
+
archive.each do |entry|
|
33
|
+
if entry.directory?
|
34
|
+
archive_dir = workspace_dir.dir(entry.full_name)
|
35
|
+
archive_dir.create
|
36
|
+
elsif entry.file?
|
37
|
+
archive_file = workspace_dir.file(entry.full_name)
|
38
|
+
archive_file.write(entry.read)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
archive.close
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Workspace
|
2
|
+
class WorkspaceFile
|
3
|
+
module Media
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def image?
|
7
|
+
["jpg", "jpeg", "gif", "png"].include?(extension)
|
8
|
+
end
|
9
|
+
|
10
|
+
def video?
|
11
|
+
["mp4"].include?(extension)
|
12
|
+
end
|
13
|
+
|
14
|
+
def audio?
|
15
|
+
["mp3"].include?(extension)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "open_uri_redirections"
|
3
|
+
|
4
|
+
module Workspace
|
5
|
+
class WorkspaceFile
|
6
|
+
module Net
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
def download(url)
|
10
|
+
url = "http:#{url}" if url[0..1] == "//"
|
11
|
+
contents = open(url, { ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, allow_redirections: :safe }).read
|
12
|
+
dir.create unless dir.exists?
|
13
|
+
write(contents)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Workspace
|
2
|
+
class WorkspaceFile
|
3
|
+
module Parse
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def read_json
|
7
|
+
JSON.parse(read)
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_yaml
|
11
|
+
Psych.load_file(to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def read_haml(options)
|
15
|
+
require "haml"
|
16
|
+
engine = Haml::Engine.new(read)
|
17
|
+
engine.render(Object.new, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'workspace/workspace_file/archive'
|
2
|
+
require 'workspace/workspace_file/media'
|
3
|
+
require 'workspace/workspace_file/net'
|
4
|
+
require 'workspace/workspace_file/parse'
|
5
|
+
|
6
|
+
module Workspace
|
7
|
+
class WorkspaceFile
|
8
|
+
include Workspace::WorkspaceFile::Archive
|
9
|
+
include Workspace::WorkspaceFile::Media
|
10
|
+
include Workspace::WorkspaceFile::Net
|
11
|
+
include Workspace::WorkspaceFile::Parse
|
12
|
+
|
13
|
+
attr_accessor :workspace, :path
|
14
|
+
|
15
|
+
def initialize(workspace, path)
|
16
|
+
@workspace = workspace
|
17
|
+
@path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def set(data)
|
21
|
+
@contents = data
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def contents
|
26
|
+
@contents ||= read
|
27
|
+
end
|
28
|
+
|
29
|
+
def replace(key, value)
|
30
|
+
contents.gsub!(key, value)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def write(data = nil)
|
35
|
+
data ||= @contents
|
36
|
+
dir.create unless dir.exists?
|
37
|
+
File.open(to_s, "wb") { |file| file << data }
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def copy(target_file)
|
42
|
+
target_file.dir.create unless target_file.dir.exists?
|
43
|
+
FileUtils.cp(to_s, target_file.to_s)
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
File.join(@workspace, @path)
|
48
|
+
end
|
49
|
+
|
50
|
+
def relative_path
|
51
|
+
@path.sub(%r{^/}, "")
|
52
|
+
end
|
53
|
+
|
54
|
+
def exists?
|
55
|
+
File.exist?(to_s) and !File.directory?(to_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
def read
|
59
|
+
File.open(to_s).read
|
60
|
+
end
|
61
|
+
|
62
|
+
def dir
|
63
|
+
Workspace::WorkspaceDir.new(@workspace, File.dirname(@path))
|
64
|
+
end
|
65
|
+
|
66
|
+
def md5
|
67
|
+
Digest::MD5.hexdigest(read)
|
68
|
+
end
|
69
|
+
|
70
|
+
def url
|
71
|
+
"file://#{absolute_path}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete!
|
75
|
+
FileUtils.rm_f(to_s)
|
76
|
+
end
|
77
|
+
|
78
|
+
def basename
|
79
|
+
File.basename(path, ".*")
|
80
|
+
end
|
81
|
+
|
82
|
+
def slug
|
83
|
+
relative_path.chomp(File.extname(self.relative_path))
|
84
|
+
end
|
85
|
+
|
86
|
+
def extension
|
87
|
+
File.extname(to_s).gsub(/^\./, "")
|
88
|
+
end
|
89
|
+
|
90
|
+
def rename!(filename)
|
91
|
+
FileUtils.mv(to_s, dir.file(filename).to_s) if exists?
|
92
|
+
@path = dir.file(filename).path
|
93
|
+
end
|
94
|
+
|
95
|
+
def absolute_path
|
96
|
+
File.absolute_path(to_s)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/workspace.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "workspace/workspace_dir"
|
2
|
+
require "workspace/workspace_file"
|
3
|
+
module Workspace
|
4
|
+
def workspace_dir(workspace, path = "")
|
5
|
+
Workspace::WorkspaceDir.new(workspace, path)
|
6
|
+
end
|
7
|
+
|
8
|
+
def workspace_file(workspace, path = "")
|
9
|
+
Workspace::WorkspaceFile.new(workspace, path)
|
10
|
+
end
|
11
|
+
end
|
data/maglove.gemspec
CHANGED
@@ -14,26 +14,26 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.description = "This gem contains development and built tools for creating MagLoft themes."
|
15
15
|
s.required_rubygems_version = '>= 2.4.7'
|
16
16
|
s.add_runtime_dependency "bundler", "~> 1.10"
|
17
|
-
s.add_runtime_dependency "dotenv", "~> 2.0"
|
18
17
|
s.add_runtime_dependency 'haml', "~> 4.0"
|
19
|
-
s.add_runtime_dependency
|
20
|
-
s.add_runtime_dependency
|
21
|
-
s.add_runtime_dependency "activesupport", "
|
22
|
-
s.add_runtime_dependency "actionpack", "
|
18
|
+
s.add_runtime_dependency "thor", "~> 0.19"
|
19
|
+
s.add_runtime_dependency 'hamloft', "~> 0.2.4"
|
20
|
+
s.add_runtime_dependency "activesupport", ">= 4.0"
|
21
|
+
s.add_runtime_dependency "actionpack", ">= 4.0"
|
22
|
+
s.add_runtime_dependency "maglove-widgets", "~> 1.0"
|
23
|
+
s.add_runtime_dependency "open_uri_redirections", "~> 0.2"
|
23
24
|
s.add_runtime_dependency "logging", "~> 2.0"
|
24
25
|
s.add_runtime_dependency "tilt", "~> 1.4"
|
25
26
|
s.add_runtime_dependency "coffee-script", "~> 2.4"
|
26
|
-
s.add_runtime_dependency "minitar", "~> 0.5"
|
27
|
-
s.add_runtime_dependency "therubyracer", "~> 0.12"
|
28
27
|
s.add_runtime_dependency "less", "~> 2.6"
|
29
28
|
s.add_runtime_dependency "sass", "~> 3.4"
|
30
|
-
s.add_runtime_dependency "
|
31
|
-
s.add_runtime_dependency "
|
32
|
-
s.add_runtime_dependency "filewatcher", "~> 0.5"
|
29
|
+
s.add_runtime_dependency "dialers", "~> 0.2"
|
30
|
+
s.add_runtime_dependency "rubyzip", "~> 1.1"
|
33
31
|
s.add_runtime_dependency "image_optim", "~> 0.21"
|
34
32
|
s.add_runtime_dependency "image_optim_pack", "~> 0.2"
|
35
|
-
s.
|
36
|
-
s.
|
33
|
+
s.add_runtime_dependency "puma", "~> 3.6"
|
34
|
+
s.add_runtime_dependency "filewatcher", "~> 0.5"
|
35
|
+
s.add_runtime_dependency "faye", "~> 1.2"
|
36
|
+
s.add_runtime_dependency "faraday", "~> 0.9"
|
37
37
|
s.add_development_dependency "rubocop", "~> 0.32"
|
38
38
|
s.files = `git ls-files`.split("\n")
|
39
39
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|