guard-tilt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - rbx-18mode
7
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'guard'
4
+ gem 'tilt'
5
+
6
+ group :development do
7
+ gem 'riot', '>= 0'
8
+ gem 'yard', '~> 0.7.4'
9
+ gem 'bundler', '~> 1.0.21'
10
+ gem 'jeweler', '~> 1.6.4'
11
+ gem 'rcov', '>= 0', :platforms => [:mri, :jruby]
12
+ end
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ffi (1.0.11)
5
+ git (1.2.5)
6
+ guard (0.10.0)
7
+ ffi (>= 0.5.0)
8
+ thor (~> 0.14.6)
9
+ jeweler (1.6.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rake (0.9.2.2)
14
+ rcov (0.9.11)
15
+ riot (0.12.5)
16
+ rr
17
+ rr (1.0.4)
18
+ thor (0.14.6)
19
+ tilt (1.3.3)
20
+ yard (0.7.4)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.21)
27
+ guard
28
+ jeweler (~> 1.6.4)
29
+ rcov
30
+ riot
31
+ tilt
32
+ yard (~> 0.7.4)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Florian Aßmann
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Guard-Tilt [![Build Status](https://secure.travis-ci.org/boof/guard-tilt.png?branch=master)](http://travis-ci.org/boof/guard-tilt) [![Maintenance Status](http://stillmaintained.com/boof/guard-tilt.png?branch=master)](http://stillmaintained.com/boof/guard-tilt) [![Dependency Status](https://gemnasium.com/boof/guard-tilt.png?branch=master)](http://gemnasium.com/boof/guard-tilt)
2
+
3
+ Guard to render templates.
4
+
5
+ ## Configuration
6
+
7
+ :context
8
+ # Class instantiated with path for template being rendered
9
+ :locals
10
+ # Hash returning instances of Hash for path, may respond to reload
11
+
12
+ # mangle the output path
13
+ Guard::Tilt.output_path = Guard::Tilt::OutputPath
14
+ # change root directory, useful for tests
15
+ Guard::Tilt.root = Dir.getwd
16
+
17
+ For details see the Guardfile template.
18
+
19
+ ## Installation
20
+
21
+ $ git clone git://github.com/boof/guard-tilt.git
22
+ $ cd guard-tilt
23
+ $ rake install
24
+
25
+ ## Setup
26
+
27
+ $ guard init tilt
28
+
29
+ ## Contributing to guard-tilt
30
+
31
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
32
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
33
+ * Fork the project
34
+ * Start a feature/bugfix branch
35
+ * Commit and push until you are happy with your contribution
36
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
37
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
38
+
39
+ ## Copyright
40
+
41
+ Copyright (c) 2012 Florian Aßmann. See LICENSE.txt for further details.
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "guard-tilt"
18
+ gem.homepage = "http://github.com/boof/guard-tilt"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Guard to render templates.}
21
+ gem.description = %Q{Guard to render templates.}
22
+ gem.email = "florian.assmann@email.de"
23
+ gem.authors = ["Florian Aßmann"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/*_test.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+ rescue Exception
44
+ warn 'No rcov available.'
45
+ end
46
+
47
+ task :default => :test
48
+
49
+ require 'yard'
50
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,83 @@
1
+ require 'guard/guard'
2
+ require 'guard/watcher'
3
+ require 'tilt'
4
+
5
+ module Guard
6
+ class Tilt < Guard
7
+
8
+ DEFAULT_CONTEXT = Struct.new(:path)
9
+ DEFAULT_LOCALS = Hash.new({})
10
+
11
+ def self.output_path=(klass) @@path = klass; end
12
+ def self.root=(root) @@root = root; end
13
+ def self.root; @@root; end
14
+
15
+ def initialize(watchers = [], options = {})
16
+ @context = options.delete(:context) || DEFAULT_CONTEXT
17
+ @locals = options.delete(:locals) || DEFAULT_LOCALS
18
+
19
+ super watchers, options
20
+ end
21
+ def start
22
+ log 'Waiting for changes'
23
+ end
24
+ def stop
25
+ end
26
+
27
+ def reload
28
+ if @locals.respond_to? :reload
29
+ log 'Reloading locals'
30
+ @locals.reload
31
+ end
32
+ end
33
+
34
+ def run_on_change(paths)
35
+ paths.each do |pathname|
36
+ full_pathname = File.expand_path pathname, @@root
37
+
38
+ next unless template = template_for(full_pathname)
39
+ next unless content = render_template(template, pathname)
40
+
41
+ path = @@path.new full_pathname
42
+ next unless write_content(content, path)
43
+
44
+ log "Rendered #{ pathname } to #{ path.to_s @@root }"
45
+ end
46
+ end
47
+ def run_all
48
+ paths = Watcher.match_files self, Dir[ File.join('**', '*') ]
49
+ run_on_change paths
50
+ end
51
+
52
+ protected
53
+
54
+ def log(message, severity = :info)
55
+ UI.send severity, "#{ self.class }: #{ message }"
56
+ end
57
+
58
+ def template_for(path)
59
+ ::Tilt.new File.expand_path(path, @@root)
60
+ rescue RuntimeError => e
61
+ log e.message, :warn
62
+ rescue Exception => e
63
+ log e.message, :error
64
+ end
65
+ def render_template(template, path)
66
+ context = @context.new path
67
+ locals = @locals.fetch path, {}
68
+
69
+ template.render(context, locals)
70
+ rescue Exception => e
71
+ log e.message, :error
72
+ end
73
+ def write_content(content, path)
74
+ path.open('w') { |f| f.write(content) }
75
+ rescue Exception => e
76
+ log e.message, :error
77
+ end
78
+
79
+ end
80
+ end
81
+
82
+ require File.expand_path('../tilt/output_path.rb', __FILE__)
83
+ Guard::Tilt.root = Dir.getwd
@@ -0,0 +1,53 @@
1
+ class Guard::Tilt::OutputPath < Struct.new(:to_str)
2
+ Guard::Tilt.output_path = self
3
+
4
+ # Template Method
5
+ def sanitize
6
+ strip_extname
7
+ end
8
+
9
+ def join(other)
10
+ new File.join(to_str, other.to_str)
11
+ end
12
+ def sub(base, root)
13
+ new to_str.sub(base, root)
14
+ end
15
+
16
+ def extname
17
+ new File.extname(to_str)
18
+ end
19
+ def basename(*args)
20
+ new File.basename(to_str, *args)
21
+ end
22
+ def dirname
23
+ new File.dirname(to_str)
24
+ end
25
+ def expand(*args)
26
+ new File.expand_path(to_str, *args)
27
+ end
28
+
29
+ def strip_extname
30
+ expand.dirname.join basename(extname)
31
+ end
32
+
33
+ def to_s(base = nil)
34
+ unless base
35
+ sanitize.to_str
36
+ else
37
+ base += File::Separator if base !~ /\/$/
38
+ sanitize.sub(base, '').to_str
39
+ end
40
+ end
41
+ def open(mode = 'r', &block)
42
+ File.open(to_s, mode, &block)
43
+ end
44
+
45
+ protected
46
+
47
+ def new(str)
48
+ instance = dup
49
+ instance.to_str = str
50
+ instance
51
+ end
52
+
53
+ end
@@ -0,0 +1,45 @@
1
+ context = Struct.new(:path) # default
2
+ =begin Context Object
3
+ context = Class.new do
4
+ def initialize(path)
5
+ end
6
+ # custom behaviour
7
+ end
8
+ =end
9
+
10
+ locals = Hash.new({}) # default
11
+ =begin Local Variables
12
+ require 'yaml'
13
+ locals, path = {}, 'locals.yml'
14
+ def locals.reload
15
+ update YAML.load_file(path)
16
+ end
17
+ locals.reload
18
+ =end
19
+
20
+ guard 'tilt', :context => context, :locals => locals do
21
+ # watch files with two extnames like index.html.erb
22
+ watch %r'views/.+\..+\..+'
23
+ end
24
+
25
+ # Guard::Tilt.root = Dir.getwd # (default: Dir.getwd)
26
+
27
+ =begin Output Path
28
+ class OuputPath < Guard::Tilt::OutputPath
29
+
30
+ BASE = File.expand_path 'views'
31
+ ROOT = File.expand_path 'public'
32
+
33
+ # By default Path#sanitize only strips an extname from itself.
34
+ #
35
+ # If you want to write the rendered output to another folder you can
36
+ # overwrite this method to return another Path object, like this:
37
+ def sanitize
38
+ super.sub BASE, ROOT
39
+ end
40
+
41
+ # ... then set the OutputPath class.
42
+ Guard::Tilt.output_path = self
43
+
44
+ end
45
+ =end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../../teststrap', __FILE__)
2
+
3
+ context "guard-tilt" do
4
+ context "output path" do
5
+
6
+ setup do
7
+ Guard::Tilt::OutputPath.new '/foo/bar/index.html.erb'
8
+ end
9
+
10
+ asserts "strip_extname" do
11
+ topic.strip_extname.to_str
12
+ end.equals '/foo/bar/index.html'
13
+
14
+ asserts "sanitize just uses strip_extname by default" do
15
+ topic.sanitize.to_str == topic.strip_extname.to_str
16
+ end
17
+ asserts "to_s uses sanitize" do
18
+ topic.to_s == topic.sanitize.to_str
19
+ end
20
+
21
+ asserts "to_s relative to '/foo'" do
22
+ topic.to_s '/foo'
23
+ end.equals 'bar/index.html'
24
+
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../teststrap', __FILE__)
2
+ Guard::Tilt.root = File.expand_path '..', __FILE__
3
+
4
+ context "guard-tilt" do
5
+
6
+ asserts "rendered content" do
7
+ Guard.guards('tilt').run_all
8
+ Content['views/index.html.erb'].content
9
+ end.equals "2"
10
+
11
+ end
@@ -0,0 +1 @@
1
+ <%= 1 + 1 %>
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'riot'
11
+ require 'guard'
12
+ require File.expand_path('../../lib/guard/tilt', __FILE__)
13
+
14
+ class Content < Guard::Tilt::OutputPath
15
+
16
+ ReturnParameter = Class.new do
17
+ def method_missing(m, *params) return m => params end
18
+ end.new
19
+
20
+ def open(mode)
21
+ (@content = yield(ReturnParameter)[:write].first).length
22
+ end
23
+ attr_reader :content
24
+
25
+ @instances = {}
26
+
27
+ def self.new(path)
28
+ @instances[path] ||= super
29
+ end
30
+ def self.[](path)
31
+ path = File.join Guard::Tilt.root, path
32
+ @instances[path]
33
+ end
34
+
35
+ end
36
+
37
+ Guard.guards # initialize guards array
38
+ Guard::Dsl.new.instance_eval do
39
+ guard('tilt') { watch %r'views/.+\..+\..+' }
40
+ end
41
+ Guard::Tilt.output_path = Content
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-tilt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Florian Aßmann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: &70240664385740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70240664385740
25
+ - !ruby/object:Gem::Dependency
26
+ name: tilt
27
+ requirement: &70240664385220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70240664385220
36
+ - !ruby/object:Gem::Dependency
37
+ name: riot
38
+ requirement: &70240664384620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70240664384620
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ requirement: &70240664383640 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70240664383640
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70240664382260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.21
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70240664382260
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70240664381420 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.4
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70240664381420
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &70240664380920 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70240664380920
91
+ description: Guard to render templates.
92
+ email: florian.assmann@email.de
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files:
96
+ - LICENSE.txt
97
+ - README.md
98
+ files:
99
+ - .document
100
+ - .travis.yml
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - VERSION
107
+ - lib/guard/tilt.rb
108
+ - lib/guard/tilt/output_path.rb
109
+ - lib/guard/tilt/templates/Guardfile
110
+ - test/guard/tilt/output_path_test.rb
111
+ - test/guard/tilt_test.rb
112
+ - test/guard/views/index.html.erb
113
+ - test/teststrap.rb
114
+ homepage: http://github.com/boof/guard-tilt
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: 2136021989564653268
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.10
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Guard to render templates.
142
+ test_files: []