voog-kit 0.3.9 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d51265487abe684ab985aa2a022320f1d90fd4c
4
- data.tar.gz: dcb97fd3850d54369acca83bb9371726739daf94
3
+ metadata.gz: 5c7ac235dd563c5bfebdf3a3c1153c9898da4810
4
+ data.tar.gz: e3d3d75ae208a8af22c2198fb8882656dc4b6051
5
5
  SHA512:
6
- metadata.gz: 60c1fe21341912b8fbca1a2fa9a35af9a1448fd92212c7aff0f10634ed5a8cf47c98c6c86732425b907418b0c458703072dff960e36f99fe82fa286a0ae417d4
7
- data.tar.gz: 045fad4b96ef25ade5b87bd3cd1c39cca8b761a64b91970b58f8afc0cbdac4ef1d7edc2957b468d36971c64387376189c979cc43f6a5f0c17c2aab674c2c2e33
6
+ metadata.gz: 9787c777adc1df1fd0d42f396677195af1a2c8766a780735f8a13f7428cea44abc0635fc78d882cb8495fc934700b413123897a8ad058dd1332992fbe68f7a5b
7
+ data.tar.gz: 04e62394e467681c2013a9683f919ee2fc93e560360bff2a3b579c7105c22f99d194ddf0e214c51111b920415ef2986832f7232326e8c2817ca24bbbfea1deaa
data/bin/kit CHANGED
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'guard'
4
3
  require 'gli'
5
4
 
6
5
  $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
7
6
  require 'json'
8
7
 
9
8
  require 'voog/dtk'
10
- require 'voog/dtk/guard'
9
+ require 'voog/dtk/watcher'
11
10
  require 'voog/dtk/filemanager'
12
11
  require 'voog/dtk/notifier'
13
12
  require 'voog_api'
@@ -234,8 +233,10 @@ command :watch do |c|
234
233
  c.flag *api_token_args
235
234
  c.flag *site_args
236
235
  c.action do |global_options, options, args|
237
- Voog::Dtk::Guuard.new(@filemanager, @debug).run
238
- sleep 0.1 while ::Guard.running
236
+ @notifier.info "Watching #{Dir.pwd}/ for changes..."
237
+ @notifier.newline
238
+ watcher = Voog::Dtk::Watcher.new(@filemanager, @debug)
239
+ watcher.run
239
240
  end
240
241
  end
241
242
 
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'fileutils'
5
5
  require 'git'
6
6
  require 'mime/types'
7
+ require 'pathname'
7
8
 
8
9
  module Voog::Dtk
9
10
  class FileManager
@@ -11,6 +12,14 @@ module Voog::Dtk
11
12
 
12
13
  BOILERPLATE_URL = 'git@github.com:Edicy/design-boilerplate.git'
13
14
 
15
+ ASSET_FOLDER_MAP = {
16
+ 'image' => 'images',
17
+ 'stylesheet' => 'stylesheets',
18
+ 'javascript' => 'javascripts',
19
+ 'font' => 'assets',
20
+ 'unknown' => 'assets'
21
+ }
22
+
14
23
  def initialize(client, opts = {})
15
24
  @client = client
16
25
  @silent = opts.fetch(:silent, false)
@@ -68,6 +77,18 @@ module Voog::Dtk
68
77
  end
69
78
  end
70
79
 
80
+ def relative_path_of(file)
81
+ if file.include? Dir.pwd
82
+ pwd = Pathname.new Dir.pwd
83
+ file_path = Pathname.new file
84
+ file_path.relative_path_from(pwd).to_s
85
+ else
86
+ file
87
+ end
88
+ rescue
89
+ file
90
+ end
91
+
71
92
  def add_to_manifest(files = nil)
72
93
  return if files.nil?
73
94
  @manifest = read_manifest
@@ -134,7 +155,7 @@ module Voog::Dtk
134
155
  def remove_from_manifest(files = nil)
135
156
  return if files.nil?
136
157
  @manifest = read_manifest
137
- files = (files.is_a? String) ? [files] : files
158
+ files = (files.is_a? String) ? [relative_path_of(files)] : files.map{ |f| relative_path_of(f) }
138
159
  files.uniq.each do |file|
139
160
  match = /^(component|layout|image|javascript|asset|stylesheet)s\/(.*)/.match(file)
140
161
  next if match.nil?
@@ -434,16 +455,8 @@ module Voog::Dtk
434
455
  && asset.respond_to?(:asset_type) \
435
456
  && (asset.respond_to?(:public_url) || asset.respond_to?(:data))
436
457
 
437
- folder_names = {
438
- 'image' => 'images',
439
- 'stylesheet' => 'stylesheets',
440
- 'javascript' => 'javascripts',
441
- 'font' => 'assets',
442
- 'unknown' => 'assets'
443
- }
444
-
445
458
  if valid
446
- folder = folder_names.fetch(asset.asset_type, 'assets')
459
+ folder = ASSET_FOLDER_MAP.fetch(asset.asset_type, 'assets')
447
460
 
448
461
  Dir.mkdir(folder) unless Dir.exist?(folder)
449
462
  Dir.chdir(folder)
@@ -652,7 +665,8 @@ module Voog::Dtk
652
665
  def layout_asset_id_map(assets=nil)
653
666
  assets ||= get_layout_assets
654
667
  assets.inject(Hash.new) do |memo, a|
655
- memo[a.public_url.gsub("http://#{@client.host}/", '')] = a.id
668
+ filename = "#{ASSET_FOLDER_MAP.fetch(a.asset_type, 'assets')}/#{a.filename}"
669
+ memo[filename] = a.id
656
670
  memo
657
671
  end
658
672
  end
@@ -669,9 +683,9 @@ module Voog::Dtk
669
683
  # Find if provided file is a directory instead
670
684
  files.each_with_index do |file, index|
671
685
  next if file.is_a? Array
672
- if Dir.exist? file
673
- subfiles = Dir.new(file).entries.reject{|e| e =~ /^(\.|\.\.)$/ } # Keep only normal subfiles
674
- subfiles.map! { |subfile| subfile = "#{file[/[^\/]*/]}/#{subfile}" } # Prepend folder name
686
+ if Dir.exist? relative_path_of(file)
687
+ subfiles = Dir.new(relative_path_of(file)).entries.reject{|e| e =~ /^(\.|\.\.)$/ } # Keep only normal subfiles
688
+ subfiles.map! { |subfile| subfile = "#{relative_path_of(file)[/[^\/]*/]}/#{subfile}" } # Prepend folder name
675
689
  files[index] = subfiles # Insert as Array so sub-subfolders won't get processed again
676
690
  end
677
691
  end
@@ -683,88 +697,89 @@ module Voog::Dtk
683
697
 
684
698
  files.each_with_index do |file, index|
685
699
  @notifier.newline if index > 0
686
- if File.exist?(file)
687
- if uploadable?(file)
688
- if file =~ /^(layout|component)s\/[^\s\/]+\.tpl$/ # if layout/component
689
- if local_layouts.include?(file)
690
- if layouts.key?(file)
691
- @notifier.info "Updating layout file #{file}..."
692
- if update_layout(layouts[file], File.read(file, encoding: 'UTF-8'))
700
+ relative_filename = relative_path_of(file)
701
+ if File.exist?(relative_filename)
702
+ if uploadable?(relative_filename)
703
+ if relative_filename =~ /^(layout|component)s\/[^\/]+\.tpl$/ # if layout/component
704
+ if local_layouts.include?(relative_filename)
705
+ if layouts.key?(relative_filename)
706
+ @notifier.info "Updating layout file #{relative_filename}..."
707
+ if update_layout(layouts[relative_filename], File.read(relative_filename, encoding: 'UTF-8'))
693
708
  @notifier.success 'OK!'
694
709
  else
695
- @notifier.error "Cannot update layout file #{file}!"
710
+ @notifier.error "Cannot update layout file #{relative_filename}!"
696
711
  end
697
712
  else
698
- @notifier.warning "Remote file #{file} not found!"
699
- @notifier.info "\nTrying to create layout file #{file}..."
700
- if create_remote_layout(file)
713
+ @notifier.warning "Remote file #{relative_filename} not found!"
714
+ @notifier.info "\nTrying to create layout file #{relative_filename}..."
715
+ if create_remote_layout(relative_filename)
701
716
  @notifier.success 'OK!'
702
717
  else
703
- @notifier.error "Unable to create layout file #{file}!"
718
+ @notifier.error "Unable to create layout file #{relative_filename}!"
704
719
  end
705
720
  end
706
721
  else
707
- @notifier.warning "Layout file #{file} not found in manifest! Skipping."
722
+ @notifier.warning "Layout file #{relative_filename} not found in manifest! Skipping."
708
723
  end
709
- elsif file =~ /^(asset|image|stylesheet|javascript)s\/[^\s\/]+\..+$/ # if other asset
710
- if local_assets.include? file
711
- if layout_assets.key? file
712
- if is_editable?(file)
713
- @notifier.info "Updating layout asset file #{file}..."
714
- if update_layout_asset(layout_assets[file], File.read(file, encoding: 'UTF-8'))
724
+ elsif relative_filename =~ /^(asset|image|stylesheet|javascript)s\/[^\/]+\..+$/ # if other asset
725
+ if local_assets.include? relative_filename
726
+ if layout_assets.key? relative_filename
727
+ if is_editable?(relative_filename)
728
+ @notifier.info "Updating layout asset file #{relative_filename}..."
729
+ if update_layout_asset(layout_assets[relative_filename], File.read(relative_filename, encoding: 'UTF-8'))
715
730
  @notifier.success 'OK!'
716
731
  else
717
- @notifier.error "Unable to update file #{file}!"
732
+ @notifier.error "Unable to update file #{relative_filename}!"
718
733
  end
719
734
  else
720
735
  if @overwrite
721
- @notifier.info "Re-uploading file #{file}..."
722
- if delete_layout_asset(layout_assets[file]) && create_remote_file(file)
736
+ @notifier.info "Re-uploading file #{relative_filename}..."
737
+ if delete_layout_asset(layout_assets[relative_filename]) && create_remote_file(relative_filename)
723
738
  @notifier.success 'OK!'
724
739
  else
725
- @notifier.error "Unable to update file #{file}!"
740
+ @notifier.error "Unable to update file #{relative_filename}!"
726
741
  end
727
742
  else
728
- @notifier.warning "Not allowed to update file #{file}!"
743
+ @notifier.warning "Not allowed to update file #{relative_filename}!"
729
744
  end
730
745
  end
731
746
  else
732
- @notifier.warning "Remote file #{file} not found!"
733
- @notifier.info "\nTrying to create file #{file}..."
734
- if create_remote_file(file)
747
+ @notifier.warning "Remote file #{relative_filename} not found!"
748
+ @notifier.info "\nTrying to create file #{relative_filename}..."
749
+ if create_remote_file(relative_filename)
735
750
  @notifier.success 'OK!'
736
751
  else
737
- @notifier.error "Unable to create file #{file}!"
752
+ @notifier.error "Unable to create file #{relative_filename}!"
738
753
  end
739
754
  end
740
755
  else
741
- @notifier.warning "Asset file #{file} not found in manifest! Skipping."
756
+ @notifier.warning "Asset file #{relative_filename} not found in manifest! Skipping."
742
757
  end
743
- elsif Dir.exist? file
744
- @notifier.warning "Not allowed to push subfolder #{file}!"
758
+ elsif Dir.exist? relative_filename
759
+ @notifier.warning "Not allowed to push subfolder #{relative_filename}!"
745
760
  else
746
- @notifier.warning "Not allowed to push file #{file}!"
761
+ @notifier.warning "Not allowed to push file #{relative_filename}!"
747
762
  end
748
763
  else
749
- @notifier.error "Cannot upload file #{file}!"
764
+ @notifier.error "Cannot upload file #{relative_filename}!"
750
765
  end
751
766
  else
752
- @notifier.error "File #{file} not found!"
767
+ @notifier.error "File #{relative_filename} not found!"
753
768
  end
754
769
  end
755
770
  @notifier.newline
756
771
  end
757
772
 
758
773
  def is_editable?(file)
759
- folder = file.split('/').first
760
- extension = file.split('/').last.split('.').last
774
+ folder = relative_path_of(file).split('/').first
775
+ extension = relative_path_of(file).split('/').last.split('.').last
761
776
 
762
777
  (%w(stylesheets javascripts).include? folder) && (%w(js css).include? extension)
763
778
  end
764
779
 
765
780
  def content_type_for(file)
766
- folder = file.split('/').first
767
- if is_editable?(file)
781
+ folder = relative_path_of(file).split('/').first
782
+ if is_editable?(relative_path_of(file))
768
783
  if folder == 'stylesheets'
769
784
  'text/css'
770
785
  elsif folder == 'javascripts'
@@ -772,7 +787,7 @@ module Voog::Dtk
772
787
  end
773
788
  else
774
789
  if folder == 'images'
775
- "image/#{file.split('/').last.split('.').last}"
790
+ "image/#{relative_path_of(file).split('/').last.split('.').last}"
776
791
  elsif folder == 'assets'
777
792
  'unknown/unknown'
778
793
  end
@@ -841,7 +856,7 @@ module Voog::Dtk
841
856
  end
842
857
 
843
858
  def add_files(names)
844
- new_files = add_to_manifest names
859
+ new_files = add_to_manifest names.map {|n| relative_path_of(n)}
845
860
  upload_files new_files.map { |f| f.fetch('file') } unless new_files.empty?
846
861
  end
847
862
 
@@ -858,14 +873,15 @@ module Voog::Dtk
858
873
  end
859
874
 
860
875
  def remove_remote_file(file)
861
- folder, filename = file.split('/')
876
+ relative_filename = relative_path_of(file)
877
+ folder, filename = relative_filename.split('/')
862
878
  return unless (folder && filename)
863
879
 
864
880
  asset_ids = layout_asset_id_map
865
881
  layout_ids = layout_id_map
866
882
 
867
- if is_asset? file
868
- id = asset_ids.fetch(file, nil)
883
+ if is_asset? relative_filename
884
+ id = asset_ids.fetch(relative_filename, nil)
869
885
 
870
886
  unless id.nil?
871
887
  if delete_layout_asset(id)
@@ -874,31 +890,31 @@ module Voog::Dtk
874
890
  @notifier.error "Failed to remove remote asset '#{filename}'!" unless @silent
875
891
  end
876
892
  end
877
- elsif is_layout? file
893
+ elsif is_layout? relative_filename
878
894
  filename = filename.gsub('.tpl', '')
879
- id = layout_ids.fetch(file, nil)
895
+ id = layout_ids.fetch(relative_filename, nil)
880
896
 
881
897
  unless id.nil?
882
898
  if delete_layout(id)
883
899
  @notifier.info "Removed remote layout '#{filename}'." unless @silent
884
900
  else
885
- @notifier.error "Failed to remove remote layout '#{file}'!" unless @silent
901
+ @notifier.error "Failed to remove remote layout '#{relative_filename}'!" unless @silent
886
902
  end
887
903
  end
888
904
  else
889
- @notifier.error "Invalid filename: '#{file}'"
905
+ @notifier.error "Invalid filename: '#{relative_filename}'"
890
906
  end
891
907
  @notifier.newline
892
908
  end
893
909
 
894
910
  def uploadable?(file)
895
911
  if file.is_a? String
896
- !(file =~ /^(component|layout|image|asset|javascript|stylesheet)s\/([^\s]+)/).nil?
912
+ !(relative_path_of(file) =~ /(component|layout|image|asset|javascript|stylesheet)s\/(.+)/).nil?
897
913
  else
898
914
  begin
899
- uploadable? file.try(:to_s)
915
+ uploadable? (relative_path_of(file).is_a? String) ? relative_path_of(file).try(:to_s) : relative_path_of(file)
900
916
  rescue
901
- raise "Cannot upload file '#{file}'!".red
917
+ raise "Cannot upload file '#{relative_path_of(file)}'!".red
902
918
  end
903
919
  end
904
920
  end
@@ -1,5 +1,5 @@
1
1
  module Voog
2
2
  module Dtk
3
- VERSION = '0.3.9'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -0,0 +1,75 @@
1
+ require 'listen'
2
+ # module Guard
3
+ # class VoogKit < Plugin
4
+ # attr_accessor :options, :filemanager, :debug
5
+
6
+ # def initialize(options = {})
7
+ # @options = options
8
+ # super(options)
9
+ # end
10
+
11
+ # def run_on_additions(paths)
12
+ # @filemanager.add_files paths
13
+ # rescue => e
14
+ # @filemanager.notifier.newline
15
+ # Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
16
+ # end
17
+
18
+ # def run_on_removals(paths)
19
+ # @filemanager.remove_files paths
20
+ # rescue => e
21
+ # @filemanager.notifier.newline
22
+ # Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
23
+ # end
24
+
25
+ # def run_on_modifications(paths)
26
+ # @filemanager.upload_files paths
27
+ # @filemanager.notifier.newline
28
+ # rescue => e
29
+ # @filemanager.notifier.newline
30
+ # Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
31
+ # end
32
+ # end
33
+ # end
34
+
35
+ module Voog::Dtk
36
+ class Watcher
37
+ def initialize(filemanager, debug=false)
38
+ paths = ['layouts/', 'components/', 'assets/', 'javascripts/', 'stylesheets/', 'images/']
39
+
40
+ @filemanager = filemanager
41
+ @debug = debug
42
+ @listener = Listen.to(*paths) do |modified, added, removed|
43
+ handle_added added unless added.empty?
44
+ handle_removed removed unless removed.empty?
45
+ handle_modified modified unless modified.empty?
46
+ end
47
+ end
48
+
49
+ def handle_added(added)
50
+ @filemanager.add_files added
51
+ rescue => e
52
+ @filemanager.notifier.newline
53
+ Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
54
+ end
55
+
56
+ def handle_removed(removed)
57
+ @filemanager.remove_files removed
58
+ rescue => e
59
+ @filemanager.notifier.newline
60
+ Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
61
+ end
62
+
63
+ def handle_modified(modified)
64
+ @filemanager.upload_files modified
65
+ rescue => e
66
+ @filemanager.notifier.newline
67
+ Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
68
+ end
69
+
70
+ def run
71
+ @listener.start
72
+ sleep
73
+ end
74
+ end
75
+ end
@@ -194,8 +194,8 @@ describe Voog::Dtk::FileManager do
194
194
  end
195
195
  end
196
196
 
197
- context 'with existing data' do
198
- it 'doesn\'t add a duplicate file' do
197
+ context 'with existing data'do
198
+ it 'doesn\'t add a duplicate file', focus: true do
199
199
  testfiles = ['components/test_layout.tpl', 'layouts/testfile.tpl']
200
200
  @filemanager.add_to_manifest testfiles
201
201
  @manifest = @filemanager.read_manifest
data/voog-kit.gemspec CHANGED
@@ -27,8 +27,8 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'guard-rspec'
28
28
 
29
29
  spec.add_runtime_dependency 'gli', '2.10.0'
30
- spec.add_runtime_dependency 'pry', '>= 0.9.12'
31
- spec.add_runtime_dependency 'guard', '>= 2.3.0', '< 3.0'
30
+ spec.add_runtime_dependency 'pry'
31
+ spec.add_runtime_dependency 'listen', '~> 3.0'
32
32
  spec.add_runtime_dependency 'git'
33
33
  spec.add_runtime_dependency 'parseconfig'
34
34
  spec.add_runtime_dependency 'voog_api', '~> 0.0.7'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voog-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikk Pristavka
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-18 00:00:00.000000000 Z
12
+ date: 2015-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -87,32 +87,26 @@ dependencies:
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 0.9.12
90
+ version: '0'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: 0.9.12
97
+ version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: guard
99
+ name: listen
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- version: 2.3.0
105
- - - "<"
102
+ - - "~>"
106
103
  - !ruby/object:Gem::Version
107
104
  version: '3.0'
108
105
  type: :runtime
109
106
  prerelease: false
110
107
  version_requirements: !ruby/object:Gem::Requirement
111
108
  requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: 2.3.0
115
- - - "<"
109
+ - - "~>"
116
110
  - !ruby/object:Gem::Version
117
111
  version: '3.0'
118
112
  - !ruby/object:Gem::Dependency
@@ -224,9 +218,9 @@ files:
224
218
  - bin/kit
225
219
  - lib/voog/dtk.rb
226
220
  - lib/voog/dtk/filemanager.rb
227
- - lib/voog/dtk/guard.rb
228
221
  - lib/voog/dtk/notifier.rb
229
222
  - lib/voog/dtk/version.rb
223
+ - lib/voog/dtk/watcher.rb
230
224
  - spec/fixtures/.DS_Store
231
225
  - spec/fixtures/.voog
232
226
  - spec/fixtures/.voog2
@@ -1,152 +0,0 @@
1
- require 'guard'
2
- require 'guard/guard'
3
- require 'guard/plugin'
4
-
5
- module Guard
6
- class Shell < Guard
7
- VERSION = '0.5.2'
8
-
9
- # Calls #run_all if the :all_on_start option is present.
10
- def start
11
- run_all if options[:all_on_start]
12
- end
13
-
14
- # Call #run_on_change for all files which match this guard.
15
- def run_all
16
- run_on_modifications(Watcher.match_files(self, Dir.glob('{,**/}*{,.*}').uniq))
17
- end
18
-
19
- # Print the result of the command(s), if there are results to be printed.
20
- def run_on_modifications(res)
21
- puts res if res
22
- end
23
- end
24
- end
25
-
26
- module Voog::Dtk
27
- class ::Guard::Watchman < ::Guard::Plugin
28
- attr_accessor :options, :filemanager, :debug
29
-
30
- # Initializes a Guard plugin.
31
- # Don't do any work here, especially as Guard plugins get initialized even if they are not in an active group!
32
- #
33
- # @param [Hash] options the custom Guard plugin options
34
- # @option options [Array<Guard::Watcher>] watchers the Guard plugin file watchers
35
- # @option options [Symbol] group the group this Guard plugin belongs to
36
- # @option options [Boolean] any_return allow any object to be returned from a watcher
37
- #
38
- def initialize(options = {})
39
- super
40
- @options = options
41
- end
42
-
43
- # Called once when Guard starts. Please override initialize method to init stuff.
44
- #
45
- # @raise [:task_has_failed] when start has failed
46
- # @return [Object] the task result
47
- #
48
- def start
49
- ::Guard::UI.info 'Guard::Voog is running'
50
- # run_all
51
- end
52
-
53
- def debug=(debug)
54
- ::Guard::UI.info 'Debug mode is enabed' if debug
55
- @debug = debug
56
- end
57
-
58
- # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
59
- #
60
- # @raise [:task_has_failed] when stop has failed
61
- # @return [Object] the task result
62
- #
63
- def stop
64
- ::Guard::UI.info 'Guard::Voog stopped'
65
- end
66
-
67
- # Called when `reload|r|z + enter` is pressed.
68
- # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
69
- #
70
- # @raise [:task_has_failed] when reload has failed
71
- # @return [Object] the task result
72
- #
73
- # def reload
74
- # end
75
-
76
- # Called when just `enter` is pressed
77
- # This method should be principally used for long action like running all specs/tests/...
78
- #
79
- # @raise [:task_has_failed] when run_all has failed
80
- # @return [Object] the task result
81
- #
82
- # def run_all
83
- # end
84
-
85
- # Default behaviour on file(s) changes that the Guard plugin watches.
86
- # @param [Array<String>] paths the changes files or paths
87
- # @raise [:task_has_failed] when run_on_change has failed
88
- # @return [Object] the task result
89
- #
90
- # def run_on_changes(paths)
91
- # end
92
-
93
- # Called on file(s) additions that the Guard plugin watches.
94
- #
95
- # @param [Array<String>] paths the changes files or paths
96
- # @raise [:task_has_failed] when run_on_additions has failed
97
- # @return [Object] the task result
98
- #
99
- def run_on_additions(paths)
100
- @filemanager.add_files paths
101
- rescue => e
102
- @filemanager.notifier.newline
103
- Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
104
- end
105
-
106
- # Called on file(s) removals that the Guard plugin watches.
107
- #
108
- # @param [Array<String>] paths the changes files or paths
109
- # @raise [:task_has_failed] when run_on_removals has failed
110
- # @return [Object] the task result
111
- #
112
- def run_on_removals(paths)
113
- @filemanager.remove_files paths
114
- rescue => e
115
- @filemanager.notifier.newline
116
- Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
117
- end
118
-
119
- # Called on file(s) modifications that the Guard plugin watches.
120
- #
121
- # @param [Array<String>] paths the changes files or paths
122
- # @raise [:task_has_failed] when run_on_modifications has failed
123
- # @return [Object] the task result
124
- #
125
- def run_on_modifications(paths)
126
- @filemanager.upload_files paths
127
- @filemanager.notifier.newline
128
- rescue => e
129
- @filemanager.notifier.newline
130
- Voog::Dtk.handle_exception e, @debug, @filemanager.notifier
131
- end
132
- end
133
-
134
- class Guuard
135
- def initialize(filemanager, debug=false)
136
- @filemanager = filemanager
137
- @debug = debug
138
- end
139
-
140
- def run
141
- guardfile = <<-EOF
142
- guard 'watchman' do
143
- watch(%r{^(layout|component|image|asset|javascript|stylesheet)s/.*})
144
- end
145
- EOF
146
-
147
- ::Guard.start(guardfile_contents: guardfile)
148
- ::Guard.guards('watchman').first.filemanager = @filemanager
149
- ::Guard.guards('watchman').first.debug = @debug
150
- end
151
- end
152
- end