guard-ejs 0.0.1

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.
@@ -0,0 +1,2 @@
1
+ guard 'ejs' do
2
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module EJSVersion
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
data/lib/guard/ejs.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'ejs'
4
+
5
+ module Guard
6
+ class EJS < Guard
7
+ def initialize(watchers = [], options = {})
8
+ super
9
+ @options = {
10
+ run_on_start: true,
11
+ namespace: 'app',
12
+ input: 'public/templates',
13
+ output: 'public/compiled/compiled.js'
14
+ }.update(options)
15
+ end
16
+
17
+ def start
18
+ UI.info 'Guard::EJS is now watching at somewhere'
19
+
20
+ # Run all if the option is true.
21
+ run_all() if @options[:run_on_start]
22
+ end
23
+
24
+ # Compile all templates.
25
+ def run_all
26
+ # Get all files.
27
+ files = Dir.glob("#{@options[:input]}/**/*").select do |path|
28
+ not File.directory? path
29
+ end
30
+
31
+ run_on_modifications files
32
+ end
33
+
34
+ # Run when the guardfile changes.
35
+ def run_on_changes(paths)
36
+ puts 'guardfile changed'
37
+ end
38
+
39
+ def run_on_additions(paths)
40
+ run_on_modifications paths
41
+ end
42
+
43
+ # Compile each template at the passed in paths.
44
+ def run_on_modifications(paths)
45
+ hash = {}
46
+
47
+ puts "paths: #{paths.inspect}"
48
+ paths.each do |path|
49
+ file = File.read path
50
+ compiled = ::EJS.compile file
51
+ hash[path] = compiled
52
+ end
53
+
54
+ # Just overwrite the whole thing for now.
55
+ FileUtils.mkdir_p File.dirname(@options[:output])
56
+
57
+ File.open(@options[:output], 'w+') do |file|
58
+ file.write "window.#{@options[:namespace]} = window.#{@options[:namespace]} || {}\n"
59
+ file.write "window.#{@options[:namespace]}.templates = {"
60
+
61
+ hash.each do |name, template|
62
+ file.write "\"#{name}\": #{template},"
63
+ end
64
+
65
+ file.write "}"
66
+ end
67
+ end
68
+
69
+ def run_on_removals(paths)
70
+ puts 'run on removals'
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-ejs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Wm. McAllister
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: ejs
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Guard gem for EJS
63
+ email:
64
+ - brian@brianmcallister.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/guard/ejs/templates/Guardfile
70
+ - lib/guard/ejs/version.rb
71
+ - lib/guard/ejs.rb
72
+ homepage: ''
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.25
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: guard-ejs will automatically precompile your ejs templates when they change.
96
+ test_files: []