Skip to content
Browse files

First commit.

  • Loading branch information...
0 parents commit 9041fe4ec5a15b3d2486801441c9e6734012b172 Florian Aßmann committed Aug 11, 2011
Showing with 85 additions and 0 deletions.
  1. +2 −0 Gemfile
  2. +4 −0 Rakefile
  3. +22 −0 guard-slim.gemspec
  4. +47 −0 lib/guard/slim.rb
  5. +5 −0 lib/guard/slim/templates/Guardfile
  6. +5 −0 lib/guard/slim/version.rb
2 Gemfile
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
4 Rakefile
@@ -0,0 +1,4 @@
+include Rake::DSL if defined?(Rake::DSL)
+
+require 'bundler'
+Bundler::GemHelper.install_tasks
22 guard-slim.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "guard/slim/version"
+
+Gem::Specification.new do |s|
+ s.name = "guard-slim"
+ s.version = Guard::Slim::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Florian Aßmann"]
+ s.email = ["florian.assmann@email.de"]
+ s.homepage = ""
+ s.summary = %q{Guard to render Slim templates}
+ s.description = %q{Guard to render Slim templates}
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency 'guard', '>= 0.4.0'
+ s.add_dependency 'slim'
+end
47 lib/guard/slim.rb
@@ -0,0 +1,47 @@
+require 'guard/guard'
+require 'guard/watchers'
+require 'slim'
+
+module Guard
+ class Slim < Guard
+ ALL = File.join '**', '*'
+ Template = ::Slim::Template
+
+ def initialize(watchers = [], options = {})
+ @root = options.delete :root
+ @locals = options.delete(:locals) || {}
+ @options = options.delete(:slim) || {}
+
+ super watchers, options
+ end
+
+ def run_all
+ run_on_change all_paths
+ end
+ def run_on_change(paths)
+ paths.each do |path|
+ content = render File.read(path)
+ open(build_path(path), 'w') { |file| file << content }
+ end
+ end
+
+ protected
+
+ def build_path(path)
+ dirname = File.dirname path
+ basename = File.basename path, '.slim'
+ basename << '.html' if File.extname(basename).empty?
+ path = File.join dirname, path
+
+
+ @root ? File.join(@root, dirname, basename) : File.join(dirname, basename)
+ end
+ def render(source)
+ Template.new( @options ) { source }.render( @locals )
+ end
+ def all_paths
+ Watchers.match_files self, Dir[ ALL ]
+ end
+
+ end
+end
5 lib/guard/slim/templates/Guardfile
@@ -0,0 +1,5 @@
+options = { :root => Dir.getwd, :locals => {}, :slim => {:pretty => true} }
+
+guard 'slim', options do
+ watch(/^.+\.html\.slim/)
+end
5 lib/guard/slim/version.rb
@@ -0,0 +1,5 @@
+module Guard
+ class Slim
+ VERSION = '0.0.1'
+ end
+end

0 comments on commit 9041fe4

Please sign in to comment.
Something went wrong with that request. Please try again.