maglove 0.8.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +157 -0
  4. data/Gemfile.lock +59 -49
  5. data/bin/maglove +13 -13
  6. data/data/maglove/export.haml +11 -0
  7. data/data/maglove/index.haml +17 -0
  8. data/data/maglove/maglove.css +62 -0
  9. data/data/maglove/maglove.haml +18 -0
  10. data/data/maglove/maglove.js +68 -0
  11. data/lib/block_resolver.rb +6 -0
  12. data/lib/ext/thor/option.rb +43 -0
  13. data/lib/magloft/api.rb +39 -0
  14. data/lib/magloft/api_caller.rb +67 -0
  15. data/lib/magloft/remote_collection.rb +50 -0
  16. data/lib/magloft/remote_resource.rb +124 -0
  17. data/lib/magloft/transformable.rb +11 -0
  18. data/lib/magloft/typeloft_block.rb +18 -0
  19. data/lib/magloft/typeloft_image.rb +18 -0
  20. data/lib/magloft/typeloft_template.rb +18 -0
  21. data/lib/magloft/typeloft_theme.rb +41 -0
  22. data/lib/magloft.rb +3 -0
  23. data/lib/maglove/application.rb +10 -12
  24. data/lib/maglove/asset/theme.rb +37 -32
  25. data/lib/maglove/commands/assets.rb +85 -0
  26. data/lib/maglove/commands/base.rb +55 -0
  27. data/lib/maglove/commands/fonts.rb +69 -0
  28. data/lib/maglove/commands/main.rb +24 -0
  29. data/lib/maglove/commands/theme.rb +197 -0
  30. data/lib/maglove/helper/log_helper.rb +3 -18
  31. data/lib/maglove/middleware/live_reload.rb +97 -0
  32. data/lib/maglove/phantom_script.rb +9 -10
  33. data/lib/maglove/server.rb +46 -78
  34. data/lib/maglove/tilt/coffee_template.rb +7 -6
  35. data/lib/maglove/tilt/haml_template.rb +4 -4
  36. data/lib/maglove/tilt/js_template.rb +8 -8
  37. data/lib/maglove/tilt/less_template.rb +5 -4
  38. data/lib/maglove/tilt/scss_template.rb +17 -11
  39. data/lib/maglove/tilt/yaml_template.rb +3 -2
  40. data/lib/maglove/version.rb +1 -1
  41. data/lib/maglove/workspace.rb +41 -0
  42. data/lib/maglove.rb +38 -49
  43. data/lib/powersnap.rb +24 -0
  44. data/lib/workspace/workspace_dir/archive.rb +18 -0
  45. data/lib/workspace/workspace_dir.rb +98 -0
  46. data/lib/workspace/workspace_file/archive.rb +45 -0
  47. data/lib/workspace/workspace_file/media.rb +19 -0
  48. data/lib/workspace/workspace_file/net.rb +18 -0
  49. data/lib/workspace/workspace_file/parse.rb +21 -0
  50. data/lib/workspace/workspace_file.rb +99 -0
  51. data/lib/workspace.rb +11 -0
  52. data/maglove.gemspec +12 -12
  53. metadata +100 -86
  54. data/data/maglove/dump.haml +0 -58
  55. data/data/maglove/sdk.haml +0 -27
  56. data/lib/ext/commander/command.rb +0 -32
  57. data/lib/ext/commander/methods.rb +0 -8
  58. data/lib/maglove/asset/base_theme.rb +0 -17
  59. data/lib/maglove/command/compile.rb +0 -44
  60. data/lib/maglove/command/compress.rb +0 -28
  61. data/lib/maglove/command/copy.rb +0 -35
  62. data/lib/maglove/command/core.rb +0 -23
  63. data/lib/maglove/command/font.rb +0 -80
  64. data/lib/maglove/command/server.rb +0 -16
  65. data/lib/maglove/command/sync.rb +0 -17
  66. data/lib/maglove/command/theme.rb +0 -175
  67. data/lib/maglove/command/util.rb +0 -45
  68. data/lib/maglove/helper/asset_helper.rb +0 -24
  69. data/lib/maglove/helper/command_helper.rb +0 -67
  70. data/lib/maglove/helper/theme_helper.rb +0 -105
  71. data/lib/maglove/server/hpub.rb +0 -185
  72. data/lib/maglove/template/tumblr.rb +0 -81
  73. data/lib/maglove/tilt/twig_template.rb +0 -49
@@ -1,23 +0,0 @@
1
- module MagLove
2
- module Command
3
- class Core
4
- include Commander::Methods
5
-
6
- def run
7
-
8
- task :validate, theme: "!" do |args, options|
9
- error! "no theme specified" if !options.theme
10
- error! "theme #{options.theme} does not exist" if !File.directory?("src/themes/#{options.theme}")
11
- debug("theme: #{options.theme}")
12
- debug("environment: #{options.production ? 'production' : 'development'}")
13
- end
14
-
15
- task :clean, theme: "!" do |args, options|
16
- theme_clean(options.theme)
17
- debug("▸ cleaned up theme directory")
18
- end
19
-
20
- end
21
- end
22
- end
23
- end
@@ -1,80 +0,0 @@
1
- module MagLove
2
- module Command
3
- class Font
4
- include Commander::Methods
5
-
6
- def get_font_styles(font_id, variant, append_dir='')
7
- font_name = font_id.gsub('-', ' ').titleize
8
- case variant
9
- when "regular"
10
- "@font-face{font-family:'#{font_name}';src:url('#{append_dir}#{font_id}-#{variant}.ttf');}\n"
11
- when "bold"
12
- "@font-face{font-family:'#{font_name}';src:url('#{append_dir}#{font_id}-#{variant}.ttf');font-weight:bold;}\n"
13
- when "italic"
14
- "@font-face{font-family:'#{font_name}';src:url('#{append_dir}#{font_id}-#{variant}.ttf');font-style:italic;}\n"
15
- when "bolditalic"
16
- "@font-face{font-family:'#{font_name}';src:url('#{append_dir}#{font_id}-#{variant}.ttf');font-weight:bold;font-style:italic;}\n"
17
- when "light"
18
- "@font-face{font-family:'#{font_name}';src:url('#{append_dir}#{font_id}-#{variant}.ttf');font-weight:300;}\n"
19
- end
20
- end
21
-
22
- def run
23
-
24
- task :compile, bucket: "cdn.magloft.com", sync: "NO" do |args, options|
25
-
26
- # clean up
27
- FileUtils.rm_rf("dist/fonts")
28
- FileUtils.mkdir_p("dist/fonts")
29
-
30
- # 1: Build font map
31
- debug("▸ building font map")
32
- font_map = {}
33
- font_files = Dir.glob("src/fonts/*/*.ttf")
34
- font_files.each do |font_file|
35
- (root_dir, font_dir, font_id, font_filename) = font_file.split("/")
36
- font_variant = font_filename.gsub("#{font_id}-", '').gsub(".ttf", '')
37
- font_map[font_id] = [] if font_map[font_id].nil?
38
- font_map[font_id].push(font_variant)
39
- end
40
-
41
- # 2: Generate stylesheets
42
- debug("▸ compiling fonts:")
43
- FileUtils.touch("dist/fonts/fonts.css")
44
- open("dist/fonts/fonts.css", 'wb') do |master_file|
45
- font_map.each do |font_id, variants|
46
- debug("~▸ compiling font '#{font_id}'")
47
-
48
- # Create font directory
49
- FileUtils.mkdir_p("dist/fonts/#{font_id}")
50
-
51
- # Copy fonts
52
- variants.each do |variant|
53
- FileUtils.copy("src/fonts/#{font_id}/#{font_id}-#{variant}.ttf", "dist/fonts/#{font_id}/#{font_id}-#{variant}.ttf")
54
- end
55
-
56
- # Create stylesheet
57
- font_style_file = "dist/fonts/#{font_id}/font.css"
58
- FileUtils.touch(font_style_file)
59
- open(font_style_file, 'wb') do |file|
60
- master_file << "/* #{font_id} (#{variants.join(", ")}) */\n"
61
- variants.each do |variant|
62
- file << get_font_styles(font_id, variant)
63
- master_file << get_font_styles(font_id, variant, "#{font_id}/")
64
- end
65
- master_file << "\n"
66
- end
67
- end
68
- end
69
- debug("▸ all font styles created")
70
-
71
- if options.sync == "YES"
72
- system "gsutil -m rsync -d -r dist/fonts gs://#{options.bucket}/fonts"
73
- debug("▸ all fonts synchronized with bucket '#{options.bucket}'")
74
- end
75
- end
76
-
77
- end
78
- end
79
- end
80
- end
@@ -1,16 +0,0 @@
1
- module MagLove
2
- module Command
3
- class Server
4
- include Commander::Methods
5
-
6
- def run
7
-
8
- task :run, theme: "!" do |args, options|
9
- info("▸ starting server for theme '#{options.theme}'")
10
- MagLove::Server.new(options.theme).run!
11
- end
12
-
13
- end
14
- end
15
- end
16
- end
@@ -1,17 +0,0 @@
1
- module MagLove
2
- module Command
3
- class Sync
4
- include Commander::Methods
5
-
6
- def run
7
-
8
- task :cdn, theme: "!", bucket: "test-cdn.magloft.com" do |args, options|
9
- error! "theme '#{options.theme}' does not exist. Did you run theme:compile yet?" if !options.theme or !File.directory?("dist/themes/#{options.theme}")
10
- info("▸ synchronizing #{options.theme} to #{options.bucket}")
11
- system "gsutil -m rsync -d -r dist/themes/#{options.theme} gs://#{options.bucket}/themes/#{options.theme}"
12
- end
13
-
14
- end
15
- end
16
- end
17
- end
@@ -1,175 +0,0 @@
1
- module MagLove
2
- module Command
3
- class Theme
4
- include Commander::Methods
5
-
6
- def run
7
-
8
- task :compile, theme: ENV["THEME"], sync: "NO", bucket: "localhost:3002" do |args, options|
9
- info("▸ compiling theme #{options.theme}")
10
- invoke_tasks(["core:validate", "core:clean", "compile:coffee", "copy:base_images", "copy:images", "compile:css", "compile:yaml", "compile:templates", "copy:thumbs", "compress:theme"], options)
11
-
12
- if options.sync == "YES"
13
- error!("▸ SYNC error: please specify a bucket to use (cdn.magloft.com, test-cdn.magloft.com)") if options.bucket == "localhost:3001"
14
- invoke_task("sync:cdn", options)
15
- end
16
- end
17
-
18
- task :deploy, theme: ENV["THEME"], out: ".", sync: "NO", bucket: "localhost:3002" do |args, options|
19
-
20
- # Compile Theme
21
- invoke_task("theme:compile", options)
22
-
23
- # Prepare Deployment Directory
24
- output_path = File.expand_path(options.out)
25
- error!("Directory '#{output_path}' does not exist!") if !File.directory?(output_path)
26
- target_path = File.join(output_path, options.theme)
27
- FileUtils.rm_r(target_path) if File.directory?(target_path)
28
- FileUtils.mkdir_p(File.join(target_path, "themes"))
29
-
30
- # Copy Assets
31
- FileUtils.cp_r(theme_dist_path(nil, options.theme), File.join(target_path, "themes/#{options.theme}"))
32
- FileUtils.cp_r(File.join("dist", "fonts"), File.join(target_path, "fonts"))
33
-
34
- # Process Templates
35
- templates = theme_config(:templates, options.theme)
36
- templates.each do |template|
37
- debug "▸ processing template #{template}"
38
-
39
- # Render template
40
- variables_yaml = theme_contents("templates/#{template}.yml", options.theme)
41
- variables = variables_yaml ? YAML.load(variables_yaml).with_indifferent_access : {}
42
- variables[:theme] = options.theme
43
- template_file = theme_glob("templates/#{template}.{html,twig,haml}", options.theme).first
44
- if !template_file.nil?
45
- asset = MagLove::Asset::Theme.new(template_file, options.theme, variables)
46
- contents = asset.contents
47
- else
48
- contents = "<p style='text-align: center; margin-top: 12px;'>ERROR: Template '#{template}' not found!</p>"
49
- end
50
-
51
- # Render Static Dump
52
- haml_contents = File.read(File.join(Gem.datadir("maglove"), "dump.haml"))
53
- html_contents = Hamloft.render(haml_contents, theme: options.theme, contents: contents, templates: templates, template: template)
54
-
55
- # Write to file
56
- File.open(File.join(target_path, "#{template}.html"), "w") {|f| f.write(html_contents) }
57
- end
58
-
59
-
60
- end
61
-
62
- task :"compile-all", sync: "NO", bucket: "localhost:3002" do |args, options|
63
- themes = Dir.chdir("src/themes") { Dir.glob("*") }
64
- themes.each do |theme|
65
- options.theme = theme
66
- invoke_task("theme:compile", options)
67
- end
68
- end
69
-
70
- task :thumbnails, theme: ENV["THEME"] do |args, options|
71
- info("▸ Starting Server")
72
- Thread.new do
73
- MagLove::Server.new(options.theme, 3000).run!
74
- end
75
- sleep 1
76
-
77
- info("▸ Generating thumbnails for theme '#{options.theme}'")
78
-
79
- templates = theme_config(:templates, options.theme)
80
- templates.each do |template|
81
- debug "▸ processing template #{template}"
82
-
83
- variables = {}
84
- variables_yaml = theme_contents("templates/#{template}.yml", options.theme)
85
- variables = YAML.load(variables_yaml).with_indifferent_access if variables_yaml
86
- variables[:theme] = options.theme
87
-
88
- # Render template
89
- template_file = theme_glob("templates/#{template}.{html,twig,haml}", options.theme).first
90
- if !template_file.nil?
91
- asset = MagLove::Asset::Theme.new(template_file, options.theme, variables)
92
- contents = asset.contents
93
- else
94
- contents = "<p style='text-align: center; margin-top: 12px;'>ERROR: Template '#{template}' not found!</p>"
95
- end
96
-
97
- # Render thumbnail html
98
- haml_contents = File.read(File.join(Gem.datadir("maglove"), "thumbnail.haml"))
99
- html = Hamloft.render(haml_contents, theme: options.theme, contents: contents)
100
-
101
- # Create thumbnail image
102
- script = PhantomScript.new('thumbnail')
103
- html_base64 = Base64.strict_encode64(html)
104
- contents = script.run(html_base64, "png", "480", "640", "1")
105
- theme_write_contents("thumbs/#{template}.png", contents, options.theme)
106
-
107
- # Optimize thumbnail image
108
- info("▸ Optimize image")
109
- begin
110
- image_optim = ImageOptim.new(pngout: false, svgo: false)
111
- image_optim.optimize_image!(theme_path("thumbs/#{template}.png", options.theme))
112
- rescue Exception => e
113
- error(e.message)
114
- error!("Missing image optimization binaries. Install via: gem install image_optim_pack")
115
- end
116
-
117
- end
118
-
119
- end
120
-
121
- task :init, theme: ENV["THEME"], base_version: "v1" do |args, options|
122
- # validate theme
123
- error! "no theme specified" if !options.theme
124
- error! "theme #{options.theme} already exists" if File.directory?("src/themes/#{options.theme}")
125
- debug("theme: #{options.theme}")
126
- debug("environment: #{options.production ? 'production' : 'development'}")
127
-
128
- # collect variables
129
- base_scaffold_dir = File.join(Gem.datadir("maglove"), "scaffold/base")
130
- base_target_dir = "src/base/#{options.base_version}"
131
- theme_scaffold_dir = File.join(Gem.datadir("maglove"), "scaffold/theme")
132
- theme_target_dir = "src/themes/#{options.theme}"
133
-
134
- # create base repository
135
- if !File.directory?(base_target_dir)
136
- FileUtils.mkdir_p("src/base")
137
- FileUtils.cp_r(base_scaffold_dir, base_target_dir)
138
- info("▸ created base theme in '#{base_target_dir}'")
139
- end
140
-
141
- # create theme repository
142
- FileUtils.mkdir_p("src/themes")
143
- FileUtils.cp_r(theme_scaffold_dir, theme_target_dir)
144
-
145
- # create yaml file
146
- yaml_contents = {
147
- "name" => options.theme.titlecase,
148
- "base_version" => options.base_version,
149
- "identifier" => options.theme,
150
- "description" => "#{options.theme.titlecase} theme created with MagLove",
151
- "templates" => ['cover', 'toc', 'article-01']
152
- }
153
- theme_write_contents("theme.yml", yaml_contents.to_yaml.gsub("---\n", ''), options.theme)
154
- info("▸ created #{options.theme} theme in '#{theme_target_dir}'")
155
- end
156
-
157
- task :dev, theme: ENV["THEME"] do |args, options|
158
- options.production = false
159
- invoke_task("theme:compile", options)
160
- invoke_task("font:compile", options)
161
- options.block = "NO"
162
- invoke_task("util:watch", options)
163
-
164
- # browser sync
165
- options.files = "dist/themes/#{options.theme}/*.css, dist/themes/#{options.theme}/*.js, dist/themes/#{options.theme}/templates/*.html, dist/themes/#{options.theme}/images/**/*"
166
- options.start_path = theme_config(:templates, options.theme).first
167
- invoke_task("util:browser_sync", options)
168
-
169
- invoke_task("server:run", options)
170
- end
171
-
172
- end
173
- end
174
- end
175
- end
@@ -1,45 +0,0 @@
1
- module MagLove
2
- module Command
3
- class Util
4
- include Commander::Methods
5
-
6
- def run
7
-
8
- task :cache_clear, bucket: "cdn.magloft.com" do |args, options|
9
- debug("▸ clearing cache for #{options.bucket}.magloft.com")
10
- system "gsutil -m setmeta -R -h 'Cache-Control:public, max-age=0, no-transform' gs://#{options.bucket}.magloft.com/themes"
11
- end
12
-
13
- task :browser_sync, theme: "!", files: "!", port: "3002", proxy_port: "3001", host: "localhost", start_path: "/", log_level: "silent" do |args, options|
14
- debug("▸ starting browser-sync")
15
- job = fork do
16
- begin
17
- system "browser-sync start --proxy #{options.host}:#{options.proxy_port} --port #{options.port} --files '#{options.files}' --startPath '#{options.start_path}' --logLevel #{options.log_level} --no-ui"
18
- rescue Exception => e
19
- info("▸ shutting down browser sync")
20
- end
21
- end
22
- Process.detach(job)
23
- end
24
-
25
- task :watch, theme: "!", block: "NO" do |args, options|
26
- info("▸ watching theme #{options.theme}")
27
- watch_config({
28
- "compile:coffee" => [theme_path("**/*.{coffee,js}", options.theme), theme_base_path("**/*.{coffee,js}", options.theme)],
29
- "compile:css" => [theme_path("**/*.{less,scss,css}", options.theme), theme_base_path("**/*.{less,scss,css}", options.theme)],
30
- "compile:templates" => [theme_path("**/*.{haml,twig,html}", options.theme)],
31
- "copy:base_images" => theme_base_path("images/**/*.{jpg,jpeg,gif,png,svg}", options.theme),
32
- "copy:images" => theme_path("images/**/*.{jpg,jpeg,gif,png,svg}", options.theme)
33
- }, options)
34
-
35
- if options.block == "YES"
36
- while true
37
- sleep 100
38
- end
39
- end
40
- end
41
-
42
- end
43
- end
44
- end
45
- end
@@ -1,24 +0,0 @@
1
- module MagLove
2
- module Helper
3
- module AssetHelper
4
-
5
- def theme_asset(path, theme=nil, locals={})
6
- theme ||= ENV["THEME"]
7
- if not File.exists?("src/themes/#{theme}/#{path}")
8
- error! "file '#{path}' not found for theme '#{theme}'"
9
- end
10
- MagLove::Asset::Theme.new(path, theme, locals.merge(theme: theme))
11
- end
12
-
13
- def base_theme_asset(path, theme=nil, version=nil)
14
- theme ||= ENV["THEME"]
15
- version ||= theme_config("base_version", theme)
16
- if not File.exists?("src/base/#{version}/#{path}")
17
- error! "file '#{path}' not found for base-theme '#{version}'"
18
- end
19
- MagLove::Asset::BaseTheme.new(path, theme, version)
20
- end
21
-
22
- end
23
- end
24
- end
@@ -1,67 +0,0 @@
1
- module MagLove
2
- module Helper
3
- module CommandHelper
4
-
5
- def task(action, option_config={}, &block)
6
- command "#{library}-#{action}" do |c|
7
- required_options = []
8
- c.syntax = "maglove #{library} #{action}"
9
- c.summary = "#{library} #{action} command"
10
- option_config.each do |key, value|
11
- if value == "!"
12
- required_options.push(key)
13
- c.option "--#{key} STRING", String, "[required]"
14
- else
15
- c.option "--#{key} STRING", String, "[default: #{value}]"
16
- end
17
- end
18
- c.task_action do |args, options|
19
- Logging.mdc["command"] = "#{library}-#{action}"
20
- required_options.each do |required_option|
21
- if !options.__hash__[required_option.to_sym]
22
- error!("missing required option '#{required_option}'")
23
- end
24
- end
25
- options.default(option_config)
26
- block.call(args, options)
27
- end
28
- end
29
- end
30
-
31
- def library
32
- self.class.name.split("::").last.underscore
33
- end
34
-
35
- def invoke_tasks(command_names, *args)
36
- command_names.each do |command_name|
37
- invoke_task(command_name, *args)
38
- end
39
- end
40
-
41
- def invoke_task(command_name, *args)
42
- command_name = command_name.gsub(":", "-")
43
- if args.length == 0
44
- command_args = []
45
- command_options = Commander::Command::Options.new
46
- elsif args.length == 1
47
- if args[0].class == Array
48
- command_args = args[0]
49
- command_options = Commander::Command::Options.new
50
- else
51
- command_args = []
52
- command_options = args[0]
53
- end
54
- elsif args.length == 2
55
- command_args = args[0]
56
- command_options = Commander::Command::Options.new
57
- else
58
- error!("invalid arguments specified for invoke_task '#{command_name}'")
59
- end
60
- command = Commander::Runner.instance.commands[command_name]
61
- error!("cannot invoke command '#{command_name}': command not found") if command.nil?
62
- command.invoke(command_args, command_options)
63
- end
64
-
65
- end
66
- end
67
- end
@@ -1,105 +0,0 @@
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
- begin
83
- invoke_task(task, options.__merge(pattern: filename))
84
- rescue Exception => e
85
- error(e.message)
86
- end
87
- end
88
- end
89
- end
90
-
91
- def watch(pattern, &block)
92
- watcher = FileWatcher.new(pattern)
93
- Thread.new(watcher) do |fw|
94
- fw.watch do |filename, event|
95
- if !File.directory?(filename) and event != :delete
96
- info("▸ file changed: #{filename}")
97
- block.call(filename, event)
98
- end
99
- end
100
- end
101
- end
102
-
103
- end
104
- end
105
- end