guard-slim 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ test/public/*
3
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ # Guard-Slim
2
+
3
+ Guard to render Slim templates.
4
+
5
+ ## Configuration
6
+
7
+ :input_root
8
+ :output_root
9
+ :context
10
+ :slim
11
+
12
+ ## Installation
13
+
14
+ $ git clone git://github.com/boof/guard-slim.git
15
+ $ cd guard-slim
16
+ $ rake
17
+ $ gem install pkg/guard-slim-0.0.1.gem
18
+
19
+ ## Setup
20
+
21
+ $ guard init slim
@@ -0,0 +1,6 @@
1
+ include Rake::DSL if defined?(Rake::DSL)
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task :default => :build
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guard/slim/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-slim"
7
+ s.version = Guard::Slim::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Florian Aßmann"]
10
+ s.email = ["florian.assmann@email.de"]
11
+ s.homepage = ""
12
+ s.summary = %q{Guard to render Slim templates}
13
+ s.description = %q{Guard to render Slim templates}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'guard', '>= 0.4.0'
21
+ s.add_dependency 'slim'
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'guard/guard'
2
+ require 'guard/watcher'
3
+ require 'slim'
4
+ require 'fileutils'
5
+
6
+ module Guard
7
+ class Slim < Guard
8
+ ALL = File.join '**', '*'
9
+ Template = ::Slim::Template
10
+
11
+ def initialize(watchers = [], options = {})
12
+ @output_root = options.delete(:output_root) || Dir.getwd
13
+ @input_root = options.delete(:input_root) || Dir.getwd
14
+ @context = options.delete(:context) || Object.new
15
+ @slim = options.delete(:slim) || {}
16
+
17
+ super watchers, options
18
+ end
19
+
20
+ def start
21
+ UI.info 'Guard-Slim: Waiting for changes...'
22
+ end
23
+
24
+ def run_all
25
+ run_on_change all_paths
26
+ end
27
+ def run_on_change(paths)
28
+ paths.each do |path|
29
+ content = render File.read(path)
30
+ open(build_path(path), 'w') do |file|
31
+ @slim[:pretty] ?
32
+ file.puts(content) :
33
+ file.write(content)
34
+ end
35
+ UI.info "Guard-Slim: Rendered #{ path } to #{ build_path path }"
36
+ end
37
+ end
38
+
39
+ protected
40
+
41
+ def build_path(path)
42
+ path = File.expand_path(path).sub @input_root, @output_root
43
+ dirname = File.dirname path
44
+
45
+ FileUtils.mkpath dirname unless File.directory? dirname
46
+
47
+ basename = File.basename path, '.slim'
48
+ basename << '.html' if File.extname(basename).empty?
49
+
50
+ File.join dirname, basename
51
+ end
52
+ def render(source)
53
+ Template.new( @slim ) { source }.render @context
54
+ end
55
+ def all_paths
56
+ Watcher.match_files self, Dir[ ALL ]
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ guard 'slim', :slim => { :pretty => true } do
2
+ watch(%r'^.+\.slim$')
3
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ class Slim
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ Context = Struct.new :title
2
+
3
+ options = {
4
+ :input_root => File.expand_path('../views', __FILE__),
5
+ :output_root => File.expand_path('../public', __FILE__),
6
+ :context => Context.new('Guard-Slim'),
7
+ :slim => { :pretty => true }
8
+ }
9
+
10
+ require File.expand_path('../../lib/guard/slim', __FILE__)
11
+
12
+ guard 'slim', options do
13
+ watch(%r'^views/.+\.slim$')
14
+ end
@@ -0,0 +1,9 @@
1
+ doctype html
2
+
3
+ title= title
4
+ meta charset="utf-8"
5
+
6
+ h1= title
7
+
8
+ p.content
9
+ | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-slim
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-08-08 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: 0.4.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: 0.4.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: slim
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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: '0'
46
+ description: Guard to render Slim templates
47
+ email:
48
+ - florian.assmann@email.de
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - README.md
56
+ - Rakefile
57
+ - guard-slim.gemspec
58
+ - lib/guard/slim.rb
59
+ - lib/guard/slim/templates/Guardfile
60
+ - lib/guard/slim/version.rb
61
+ - test/Guardfile
62
+ - test/views/index.slim
63
+ homepage: ''
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Guard to render Slim templates
87
+ test_files:
88
+ - test/Guardfile
89
+ - test/views/index.slim