maglove 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +137 -0
- data/README.md +26 -0
- data/bin/maglove +21 -0
- data/data/maglove/scaffold/base/base.coffee +1 -0
- data/data/maglove/scaffold/base/base.less +26 -0
- data/data/maglove/scaffold/base/images/base/loading-bars.svg +17 -0
- data/data/maglove/scaffold/base/less/base/animations.less +301 -0
- data/data/maglove/scaffold/base/less/base/blockquotes.less +23 -0
- data/data/maglove/scaffold/base/less/base/buttons.less +76 -0
- data/data/maglove/scaffold/base/less/base/code.less +19 -0
- data/data/maglove/scaffold/base/less/base/forms.less +115 -0
- data/data/maglove/scaffold/base/less/base/global.less +142 -0
- data/data/maglove/scaffold/base/less/base/grid-minimal.less +146 -0
- data/data/maglove/scaffold/base/less/base/grid-non-responsive.less +63 -0
- data/data/maglove/scaffold/base/less/base/grid.less +267 -0
- data/data/maglove/scaffold/base/less/base/helpers.less +146 -0
- data/data/maglove/scaffold/base/less/base/images.less +8 -0
- data/data/maglove/scaffold/base/less/base/lists.less +23 -0
- data/data/maglove/scaffold/base/less/base/mixins.less +107 -0
- data/data/maglove/scaffold/base/less/base/print.less +35 -0
- data/data/maglove/scaffold/base/less/base/resets.less +27 -0
- data/data/maglove/scaffold/base/less/base/tables.less +29 -0
- data/data/maglove/scaffold/base/less/core/alignments.less +17 -0
- data/data/maglove/scaffold/base/less/core/cleanup.less +8 -0
- data/data/maglove/scaffold/base/less/core/editor.less +23 -0
- data/data/maglove/scaffold/base/less/core/typography.less +74 -0
- data/data/maglove/scaffold/base/less/vendor/flex-video.less +22 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/animated.less +34 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/bordered-pulled.less +16 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/core.less +13 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/fixed-width.less +6 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/font-awesome.less +17 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/icons.less +596 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/larger.less +13 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/list.less +19 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/mixins.less +27 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/rotated-flipped.less +20 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/stacked.less +20 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome/variables.less +606 -0
- data/data/maglove/scaffold/base/less/vendor/font-awesome.less +16 -0
- data/data/maglove/scaffold/base/less/vendor/image-loader.less +15 -0
- data/data/maglove/scaffold/base/less/vendor/magnific-popup.less +363 -0
- data/data/maglove/scaffold/base/less/widgets/banner.less +3 -0
- data/data/maglove/scaffold/base/less/widgets/button.less +26 -0
- data/data/maglove/scaffold/base/less/widgets/callout.less +3 -0
- data/data/maglove/scaffold/base/less/widgets/columns.less +25 -0
- data/data/maglove/scaffold/base/less/widgets/container.less +114 -0
- data/data/maglove/scaffold/base/less/widgets/feedback.less +11 -0
- data/data/maglove/scaffold/base/less/widgets/heading.less +8 -0
- data/data/maglove/scaffold/base/less/widgets/horizontal_rule.less +113 -0
- data/data/maglove/scaffold/base/less/widgets/image.less +85 -0
- data/data/maglove/scaffold/base/less/widgets/paragraph.less +3 -0
- data/data/maglove/scaffold/base/variables.less +75 -0
- data/data/maglove/scaffold/base/vendor/jquery.js +4 -0
- data/data/maglove/scaffold/theme/images/logo.png +0 -0
- data/data/maglove/scaffold/theme/images/pattern/symphony.png +0 -0
- data/data/maglove/scaffold/theme/less/base/variables.less +25 -0
- data/data/maglove/scaffold/theme/templates/article-01.haml +41 -0
- data/data/maglove/scaffold/theme/templates/cover.haml +27 -0
- data/data/maglove/scaffold/theme/templates/toc.haml +34 -0
- data/data/maglove/scaffold/theme/templates/toc.yml +12 -0
- data/data/maglove/scaffold/theme/theme.coffee +1 -0
- data/data/maglove/scaffold/theme/theme.less +4 -0
- data/data/maglove/sdk.coffee +22 -0
- data/data/maglove/sdk.haml +18 -0
- data/data/maglove/sdk.less +60 -0
- data/data/maglove/thumbnail.haml +11 -0
- data/data/maglove/thumbnail.js +160 -0
- data/data/maglove/vendor.js +4 -0
- data/lib/ext/commander/command.rb +32 -0
- data/lib/ext/commander/methods.rb +8 -0
- data/lib/maglove/application.rb +46 -0
- data/lib/maglove/asset/base_theme.rb +17 -0
- data/lib/maglove/asset/theme.rb +83 -0
- data/lib/maglove/command/compile.rb +40 -0
- data/lib/maglove/command/compress.rb +36 -0
- data/lib/maglove/command/copy.rb +35 -0
- data/lib/maglove/command/core.rb +23 -0
- data/lib/maglove/command/font.rb +80 -0
- data/lib/maglove/command/server.rb +16 -0
- data/lib/maglove/command/sync.rb +17 -0
- data/lib/maglove/command/theme.rb +132 -0
- data/lib/maglove/command/util.rb +45 -0
- data/lib/maglove/helper/asset_helper.rb +24 -0
- data/lib/maglove/helper/command_helper.rb +67 -0
- data/lib/maglove/helper/log_helper.rb +42 -0
- data/lib/maglove/helper/theme_helper.rb +101 -0
- data/lib/maglove/phantom_script.rb +45 -0
- data/lib/maglove/server.rb +80 -0
- data/lib/maglove/template/tumblr.rb +81 -0
- data/lib/maglove/tilt/coffee_template.rb +47 -0
- data/lib/maglove/tilt/haml_template.rb +20 -0
- data/lib/maglove/tilt/js_template.rb +38 -0
- data/lib/maglove/tilt/less_template.rb +18 -0
- data/lib/maglove/tilt/twig_template.rb +49 -0
- data/lib/maglove/tilt/yaml_template.rb +19 -0
- data/lib/maglove/version.rb +3 -0
- data/lib/maglove.rb +46 -0
- data/maglove.gemspec +39 -0
- metadata +427 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
module MagLove
|
2
|
+
module Helper
|
3
|
+
module ThemeHelper
|
4
|
+
|
5
|
+
@@config = {}
|
6
|
+
|
7
|
+
def theme_clean(theme=nil)
|
8
|
+
FileUtils.rm_rf(theme_dist_path(nil, theme))
|
9
|
+
FileUtils.mkdir_p(theme_dist_path(nil, theme))
|
10
|
+
end
|
11
|
+
|
12
|
+
def theme_config(key=nil, theme)
|
13
|
+
if not @@config[theme]
|
14
|
+
@@config[theme] = YAML.load(theme_contents("theme.yml", theme))
|
15
|
+
end
|
16
|
+
if key.nil?
|
17
|
+
@@config[theme]
|
18
|
+
else
|
19
|
+
@@config[theme][key.to_s]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def theme_glob(pattern, theme)
|
24
|
+
glob = []
|
25
|
+
Dir.chdir(theme_path(nil, theme)) do
|
26
|
+
glob = Dir.glob(pattern)
|
27
|
+
end
|
28
|
+
glob
|
29
|
+
end
|
30
|
+
|
31
|
+
def theme_path(path=nil, theme)
|
32
|
+
path.nil? ? "src/themes/#{theme}" : "src/themes/#{theme}/#{path}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def theme_dist_path(path=nil, theme)
|
36
|
+
path.nil? ? "dist/themes/#{theme}" : "dist/themes/#{theme}/#{path}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def theme_contents(path, theme)
|
40
|
+
if File.exists?(theme_path(path, theme))
|
41
|
+
File.read(theme_path(path, theme))
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def theme_write_contents(path, contents, theme)
|
48
|
+
File.open(theme_path(path, theme), "w") {|f| f.write(contents) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def theme_dist_contents(path, theme)
|
52
|
+
File.read(theme_dist_path(path, theme))
|
53
|
+
end
|
54
|
+
|
55
|
+
def theme_base_glob(pattern, theme)
|
56
|
+
glob = []
|
57
|
+
Dir.chdir(theme_base_path(nil, theme)) do
|
58
|
+
glob = Dir.glob(pattern)
|
59
|
+
end
|
60
|
+
glob
|
61
|
+
end
|
62
|
+
|
63
|
+
def theme_base_path(path=nil, theme)
|
64
|
+
path.nil? ? "src/base/#{theme_config(:base_version, theme)}" : "src/base/#{theme_config(:base_version, theme)}/#{path}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def theme_dist_glob(pattern, theme)
|
68
|
+
Dir.glob("dist/themes/#{theme}/#{pattern}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def theme_watch(pattern, theme, &block)
|
72
|
+
watch(theme_path(pattern, theme), &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
def theme_base_watch(pattern, theme, &block)
|
76
|
+
watch(theme_base_path(pattern, theme), &block)
|
77
|
+
end
|
78
|
+
|
79
|
+
def watch_config(config, options)
|
80
|
+
config.each do |task, pattern|
|
81
|
+
watch(pattern) do |filename, event|
|
82
|
+
invoke_task(task, options.__merge(pattern: filename))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def watch(pattern, &block)
|
88
|
+
watcher = FileWatcher.new(pattern)
|
89
|
+
Thread.new(watcher) do |fw|
|
90
|
+
fw.watch do |filename, event|
|
91
|
+
if !File.directory?(filename) and event != :delete
|
92
|
+
info("▸ file changed: #{filename}")
|
93
|
+
block.call(filename, event)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module MagLove
|
4
|
+
class PhantomScript
|
5
|
+
attr_accessor :running, :script, :options, :path, :log_file
|
6
|
+
|
7
|
+
def initialize(script, options={})
|
8
|
+
@running = false
|
9
|
+
@script = script
|
10
|
+
@options = options.merge({
|
11
|
+
script_path: Gem.datadir("maglove")
|
12
|
+
})
|
13
|
+
@path = File.absolute_path(File.join(@options[:script_path], "#{@script}.js"))
|
14
|
+
throw "Script #{script} not found at #{@path}" if not File.exists?(@path)
|
15
|
+
@log_file = Tempfile.new('pslog')
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(*args)
|
19
|
+
start = Time.now
|
20
|
+
@running = true
|
21
|
+
cmd = "phantomjs #{@path} #{@log_file.path} #{args.join(' ')}"
|
22
|
+
|
23
|
+
# log phantomjs info
|
24
|
+
@log_thread = Thread.new{
|
25
|
+
f = File.open(@log_file.path, "r")
|
26
|
+
f.seek(0, IO::SEEK_END)
|
27
|
+
puts "phantom@0ms ▸ (start)"
|
28
|
+
while @running do
|
29
|
+
select([f])
|
30
|
+
line = f.gets
|
31
|
+
puts "phantom@#{((Time.now - start) * 1000.0).to_i}ms ▸ #{line}" if line
|
32
|
+
end
|
33
|
+
}
|
34
|
+
|
35
|
+
# run command and return result
|
36
|
+
result = `#{cmd}`
|
37
|
+
@running = false
|
38
|
+
(result == "ERROR") ? false : result
|
39
|
+
ensure
|
40
|
+
@log_file.close
|
41
|
+
@log_file.unlink
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module MagLove
|
2
|
+
class Server
|
3
|
+
include Commander::Methods
|
4
|
+
attr_accessor :port, :root, :theme, :webrick
|
5
|
+
|
6
|
+
def initialize(theme, port=3001)
|
7
|
+
self.theme = theme
|
8
|
+
self.port = port
|
9
|
+
self.root = "dist/"
|
10
|
+
|
11
|
+
# create server
|
12
|
+
self.webrick = WEBrick::HTTPServer.new(
|
13
|
+
Port: self.port,
|
14
|
+
DocumentRoot: self.root,
|
15
|
+
Logger: WEBrick::Log.new("/dev/null"),
|
16
|
+
AccessLog: []
|
17
|
+
)
|
18
|
+
|
19
|
+
# template view actions
|
20
|
+
templates = theme_config(:templates, self.theme)
|
21
|
+
templates.each do |template|
|
22
|
+
mount("/#{template}") do |req, res|
|
23
|
+
debug("▸ rendering template: #{template}")
|
24
|
+
|
25
|
+
# Prepare variables
|
26
|
+
variables = {}
|
27
|
+
variables_yaml = theme_contents("templates/#{template}.yml", self.theme)
|
28
|
+
variables = YAML.load(variables_yaml).with_indifferent_access if variables_yaml
|
29
|
+
variables[:theme] = self.theme
|
30
|
+
|
31
|
+
# Render template
|
32
|
+
template_file = theme_glob("templates/#{template}.{html,twig,haml}", self.theme).first
|
33
|
+
if !template_file.nil?
|
34
|
+
asset = MagLove::Asset::Theme.new(template_file, self.theme, variables)
|
35
|
+
contents = asset.contents
|
36
|
+
else
|
37
|
+
contents = "<p style='text-align: center; margin-top: 12px;'>ERROR: Template '#{template}' not found!</p>"
|
38
|
+
end
|
39
|
+
|
40
|
+
# render editor view
|
41
|
+
haml_contents = File.read(File.join(Gem.datadir("maglove"), "sdk.haml"))
|
42
|
+
res.body = Hamloft.render(haml_contents, theme: self.theme, contents: contents, templates: templates, template: template)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
mount("/sdk.js") do |req, res|
|
47
|
+
js_contents = File.read(File.join(Gem.datadir("maglove"), "vendor.js"))
|
48
|
+
coffee_contents = File.read(File.join(Gem.datadir("maglove"), "sdk.coffee"))
|
49
|
+
res.content_type = "text/javascript"
|
50
|
+
res.body = [js_contents, CoffeeScript.compile(coffee_contents, bare: true)].join("\n")
|
51
|
+
end
|
52
|
+
|
53
|
+
mount("/sdk.css") do |req, res|
|
54
|
+
less_contents = File.read(File.join(Gem.datadir("maglove"), "sdk.less"))
|
55
|
+
parser = ::Less::Parser.new(relativeUrls: false)
|
56
|
+
res.content_type = "text/css"
|
57
|
+
res.body = parser.parse(less_contents).to_css
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def mount_template(path, view, options={})
|
62
|
+
mount(path) do |req, res|
|
63
|
+
engine = Haml::Engine.new(parse_view(view))
|
64
|
+
res.body = engine.render(Object.new, options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def mount(path, &block)
|
69
|
+
self.webrick.mount_proc(path, &block)
|
70
|
+
end
|
71
|
+
|
72
|
+
def run!
|
73
|
+
trap 'INT' do
|
74
|
+
self.webrick.shutdown
|
75
|
+
end
|
76
|
+
self.webrick.start
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module MagLove
|
2
|
+
module Template
|
3
|
+
class Tumblr < Hamloft::Template
|
4
|
+
|
5
|
+
def chunks
|
6
|
+
self.doc.children
|
7
|
+
end
|
8
|
+
|
9
|
+
def container(&block)
|
10
|
+
haml.container_widget(padding_left: "0em", padding_right: "0em", &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def process_chunk(chunk)
|
14
|
+
case chunk.name
|
15
|
+
when "text"
|
16
|
+
haml.paragraph_widget({margin_left: "2em", margin_right: "2em"}, chunk.text)
|
17
|
+
when "p"
|
18
|
+
haml.paragraph_widget({margin_left: "2em", margin_right: "2em"}, chunk.text)
|
19
|
+
when "ol", "ul"
|
20
|
+
haml.paragraph_widget({margin_left: "2em", margin_right: "2em"}) do
|
21
|
+
haml.haml_tag chunk.name, class: "user-list" do
|
22
|
+
chunk.children.each do |child|
|
23
|
+
haml.haml_tag :li do
|
24
|
+
haml.haml_concat child.text
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
when "h1", "h2", "h3", "h4", "h5"
|
30
|
+
haml.heading_widget({type: chunk.name, margin_left: "2em", margin_right: "2em", margin_bottom: "1em"}, chunk.text)
|
31
|
+
when "a"
|
32
|
+
if chunk.css("img").length > 0
|
33
|
+
haml.image_widget_link(href: chunk.attribute("href").to_s, source: chunk.css("img").first.attribute("src").to_s)
|
34
|
+
else
|
35
|
+
haml.paragraph_widget({margin_left: "2em", margin_right: "2em"}, chunk.text) do
|
36
|
+
haml.link(chunk.attribute("href").to_s)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
when "figure"
|
40
|
+
case chunk.children.first.name
|
41
|
+
when "img"
|
42
|
+
haml.image_widget(source: chunk.children.first.attribute("src").to_s, margin_bottom: "1em")
|
43
|
+
when "iframe"
|
44
|
+
iframe_url = chunk.children.first.attribute("src").value
|
45
|
+
if iframe_url.include?("screen.yahoo.com") and match = iframe_url.match("screen\.yahoo\.com\/([a-z0-9\-]+)\.html")
|
46
|
+
haml.yahoo_screen_widget(yahoo_screen_id: match[1], margin_bottom: "1em")
|
47
|
+
elsif iframe_url.include?("www.youtube.com") and match = iframe_url.match("www\.youtube\.com\/.*\/([a-zA-Z0-9]+)")
|
48
|
+
haml.youtube_widget(youtube_id: match[1], margin_bottom: "1em")
|
49
|
+
else
|
50
|
+
puts "-- unhandled iframe: #{iframe_url}"
|
51
|
+
end
|
52
|
+
else
|
53
|
+
puts "-- unhandled figure: #{chunk.children.first.name}"
|
54
|
+
end
|
55
|
+
when "div"
|
56
|
+
if chunk.attribute("class").to_s == "sponlogo"
|
57
|
+
haml.container_widget background_color: "white", padding_left: "1em", padding_right: "1em", padding_bottom: "0.5em", padding_top: "1em" do
|
58
|
+
haml.columns_widget columns: "3x9" do |row|
|
59
|
+
haml.column row do
|
60
|
+
process_chunk(chunk.children()[0])
|
61
|
+
end
|
62
|
+
haml.column row do
|
63
|
+
haml.paragraph_widget({align: "right"}, chunk.children()[1].text)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
else
|
68
|
+
haml.container_widget do
|
69
|
+
chunk.children.each do |child_chunk|
|
70
|
+
process_chunk(child_chunk)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
puts "-- unhandled chunk: #{chunk.name}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module MagLove
|
2
|
+
module Tilt
|
3
|
+
class CoffeeTemplate < ::Tilt::Template
|
4
|
+
self.default_mime_type = 'application/javascript'
|
5
|
+
|
6
|
+
def self.engine_initialized?
|
7
|
+
defined? ::CoffeeScript
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize_engine
|
11
|
+
require_template_library 'coffee_script'
|
12
|
+
end
|
13
|
+
|
14
|
+
def prepare
|
15
|
+
options[:bare] = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def evaluate(scope, locals, &block)
|
19
|
+
@output = CoffeeScript.compile(@data, options)
|
20
|
+
|
21
|
+
# handle includes
|
22
|
+
@output.gsub(/^include\("([^"]+)"\);$/) do |match|
|
23
|
+
path = Regexp.last_match[1]
|
24
|
+
path = "#{path}.coffee" if File.extname(path).empty?
|
25
|
+
include_path = File.absolute_path(path, File.dirname(file))
|
26
|
+
|
27
|
+
# check if base path exists
|
28
|
+
if not File.exists?(include_path)
|
29
|
+
include_path = File.absolute_path(path, locals[:base_path])
|
30
|
+
end
|
31
|
+
|
32
|
+
if File.exists?(include_path)
|
33
|
+
include_template = ::Tilt.new(include_path)
|
34
|
+
include_template.render(nil, locals)
|
35
|
+
else
|
36
|
+
raise "Path not found: #{include_path}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def allows_script?
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MagLove
|
2
|
+
module Tilt
|
3
|
+
class HamlTemplate < ::Tilt::Template
|
4
|
+
self.default_mime_type = 'theme/html'
|
5
|
+
|
6
|
+
def prepare
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def evaluate(scope, locals, &block)
|
11
|
+
@output ||= Hamloft::Engine.new(data, {remove_whitespace: true}).render(scope, locals)
|
12
|
+
end
|
13
|
+
|
14
|
+
def allows_script?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module MagLove
|
2
|
+
module Tilt
|
3
|
+
class JsTemplate < ::Tilt::Template
|
4
|
+
self.default_mime_type = 'application/javascript'
|
5
|
+
|
6
|
+
def prepare
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def evaluate(scope, locals, &block)
|
11
|
+
|
12
|
+
# handle includes
|
13
|
+
@data = @data.gsub(/^\/\/=\srequire\s(.+)$/) do |match|
|
14
|
+
path = Regexp.last_match[1]
|
15
|
+
include_path = File.absolute_path(path, File.dirname(file))
|
16
|
+
|
17
|
+
# check if base path exists
|
18
|
+
if not File.exists?(include_path)
|
19
|
+
include_path = File.absolute_path(path, locals[:base_path])
|
20
|
+
end
|
21
|
+
|
22
|
+
if File.exists?(include_path)
|
23
|
+
include_template = ::Tilt.new(include_path)
|
24
|
+
include_contents = include_template.render(nil, locals)
|
25
|
+
else
|
26
|
+
raise "Path not found: #{include_path}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@output = @data
|
31
|
+
end
|
32
|
+
|
33
|
+
def allows_script?
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MagLove
|
2
|
+
module Tilt
|
3
|
+
class LessTemplate < ::Tilt::Template
|
4
|
+
self.default_mime_type = 'theme/html'
|
5
|
+
|
6
|
+
def prepare
|
7
|
+
@parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line, :relativeUrls => false)
|
8
|
+
end
|
9
|
+
|
10
|
+
def evaluate(scope, locals, &block)
|
11
|
+
prepared_data = "@base: \"#{locals[:base_path].sub("src/", "../../")}\";\n#{data}"
|
12
|
+
@engine = @parser.parse(prepared_data)
|
13
|
+
@output ||= @engine.to_css(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module MagLove
|
5
|
+
module Tilt
|
6
|
+
class TwigTemplate < ::Tilt::Template
|
7
|
+
self.default_mime_type = 'theme/html'
|
8
|
+
|
9
|
+
def initialize_engine
|
10
|
+
install_php_dependencies
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare; end
|
14
|
+
|
15
|
+
def evaluate(scope, locals, &block)
|
16
|
+
return @output if not @output.nil?
|
17
|
+
yaml_file = Tempfile.new(['context-', '.yml'])
|
18
|
+
yaml_data = locals.merge(scope.is_a?(Hash) ? scope : {}).stringify_keys
|
19
|
+
begin
|
20
|
+
File.open(yaml_file.path, 'w'){|file| file.write(yaml_data.to_yaml)}
|
21
|
+
@output = `php #{binary_path} render -d '#{File.dirname(file)}' -y '#{yaml_file.path}' '#{File.basename(file)}'`
|
22
|
+
rescue
|
23
|
+
raise
|
24
|
+
ensure
|
25
|
+
yaml_file.close
|
26
|
+
yaml_file.unlink
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def install_php_dependencies
|
33
|
+
if !File.exists?(binary_path)
|
34
|
+
require 'open-uri'
|
35
|
+
File.open(binary_path, "wb") do |saved_file|
|
36
|
+
open("https://github.com/MagLoft/twigster/raw/master/twigster.phar", "rb") do |read_file|
|
37
|
+
saved_file.write(read_file.read)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def binary_path
|
44
|
+
File.join(Gem.datadir("maglove"), "twigster.phar")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MagLove
|
2
|
+
module Tilt
|
3
|
+
class YamlTemplate < ::Tilt::Template
|
4
|
+
self.default_mime_type = 'application/json'
|
5
|
+
|
6
|
+
def prepare
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def evaluate(scope, locals, &block)
|
11
|
+
@output ||= YAML.load(data).to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
def allows_script?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/maglove.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "tilt"
|
2
|
+
require "hamloft"
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler"
|
6
|
+
require "active_support/all"
|
7
|
+
require "dotenv"
|
8
|
+
require "webrick"
|
9
|
+
require "filewatcher"
|
10
|
+
require "logging"
|
11
|
+
require "coffee_script"
|
12
|
+
require "therubyracer"
|
13
|
+
require "less"
|
14
|
+
require "commander"
|
15
|
+
require "image_optim"
|
16
|
+
require "zlib"
|
17
|
+
require "archive/tar/minitar"
|
18
|
+
|
19
|
+
require "maglove/version"
|
20
|
+
require "maglove/tilt/twig_template"
|
21
|
+
require "maglove/tilt/haml_template"
|
22
|
+
require "maglove/tilt/less_template"
|
23
|
+
require "maglove/tilt/coffee_template"
|
24
|
+
require "maglove/tilt/js_template"
|
25
|
+
require "maglove/tilt/yaml_template"
|
26
|
+
require "maglove/helper/log_helper"
|
27
|
+
require "maglove/helper/theme_helper"
|
28
|
+
require "maglove/helper/asset_helper"
|
29
|
+
require "maglove/helper/command_helper"
|
30
|
+
require "ext/commander/command"
|
31
|
+
require "ext/commander/methods"
|
32
|
+
require "maglove/command/theme"
|
33
|
+
require "maglove/command/core"
|
34
|
+
require "maglove/command/compile"
|
35
|
+
require "maglove/command/compress"
|
36
|
+
require "maglove/command/copy"
|
37
|
+
require "maglove/command/util"
|
38
|
+
require "maglove/command/font"
|
39
|
+
require "maglove/command/sync"
|
40
|
+
require "maglove/command/server"
|
41
|
+
require "maglove/phantom_script"
|
42
|
+
require "maglove/application"
|
43
|
+
require "maglove/asset/theme"
|
44
|
+
require "maglove/asset/base_theme"
|
45
|
+
require "maglove/server"
|
46
|
+
require "maglove/template/tumblr"
|
data/maglove.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'maglove/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "maglove"
|
7
|
+
s.version = MagLove::VERSION
|
8
|
+
s.licenses = ["BSD-3-Clause"]
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Tobias Strebitzer"]
|
11
|
+
s.email = ["tobias.strebitzer@magloft.com"]
|
12
|
+
s.homepage = "https://github.com/MagLoft/maglove"
|
13
|
+
s.summary = "MagLove - MagLoft Theme Toolkit."
|
14
|
+
s.description = "This gem contains development and built tools for creating MagLoft themes."
|
15
|
+
s.required_rubygems_version = '>= 2.4.7'
|
16
|
+
s.add_runtime_dependency "bundler", "~> 1.10"
|
17
|
+
s.add_runtime_dependency "dotenv", "~> 2.0"
|
18
|
+
s.add_runtime_dependency 'haml', "~> 4.0"
|
19
|
+
s.add_runtime_dependency 'hamloft', "~> 0.1"
|
20
|
+
s.add_runtime_dependency "rubyzip", "~> 1.1"
|
21
|
+
s.add_runtime_dependency "activesupport", "~> 4.2"
|
22
|
+
s.add_runtime_dependency "logging", "~> 2.0"
|
23
|
+
s.add_runtime_dependency "tilt", "~> 1.4"
|
24
|
+
s.add_runtime_dependency "coffee-script", "~> 2.4"
|
25
|
+
s.add_runtime_dependency "minitar", "~> 0.5"
|
26
|
+
s.add_runtime_dependency "therubyracer", "~> 0.12"
|
27
|
+
s.add_runtime_dependency "less", "~> 2.6"
|
28
|
+
s.add_runtime_dependency "webrick", "~> 1.3"
|
29
|
+
s.add_runtime_dependency "commander", "~> 4.3"
|
30
|
+
s.add_runtime_dependency "filewatcher", "~> 0.5"
|
31
|
+
s.add_runtime_dependency "image_optim", "~> 0.21"
|
32
|
+
s.add_runtime_dependency "image_optim_pack", "~> 0.2"
|
33
|
+
s.add_development_dependency "rspec", "~> 3.3"
|
34
|
+
s.add_development_dependency "pry", "~> 0.10"
|
35
|
+
s.add_development_dependency "rubocop", "~> 0.32"
|
36
|
+
s.files = `git ls-files`.split("\n")
|
37
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
38
|
+
s.require_path = 'lib'
|
39
|
+
end
|