thorero-haml 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 YOUR NAME
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.
data/README ADDED
@@ -0,0 +1,4 @@
1
+ merb-haml
2
+ =========
3
+
4
+ A plugin for the Merb framework that provides ...
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require "extlib"
4
+ require 'merb-core/tasks/merb_rake_helper'
5
+ require "spec/rake/spectask"
6
+
7
+ ##############################################################################
8
+ # Package && release
9
+ ##############################################################################
10
+ RUBY_FORGE_PROJECT = "thorero"
11
+ PROJECT_URL = "http://merbivore.com"
12
+ PROJECT_SUMMARY = "Merb plugin that provides HAML support"
13
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY
14
+
15
+ GEM_AUTHOR = "Yehuda Katz"
16
+ GEM_EMAIL = "ykatz@engineyard.com"
17
+
18
+ GEM_NAME = "thorero-haml"
19
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
21
+
22
+ RELEASE_NAME = "REL #{GEM_VERSION}"
23
+
24
+ require "extlib/tasks/release"
25
+
26
+ spec = Gem::Specification.new do |s|
27
+ s.rubyforge_project = RUBY_FORGE_PROJECT
28
+ s.name = GEM_NAME
29
+ s.version = GEM_VERSION
30
+ s.platform = Gem::Platform::RUBY
31
+ s.has_rdoc = true
32
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
33
+ s.summary = PROJECT_SUMMARY
34
+ s.description = PROJECT_DESCRIPTION
35
+ s.author = GEM_AUTHOR
36
+ s.email = GEM_EMAIL
37
+ s.homepage = PROJECT_URL
38
+ s.add_dependency('merb-core', '>= 0.9.4')
39
+ s.add_dependency('haml', '>= 1.8.2')
40
+ s.require_path = 'lib'
41
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
42
+ end
43
+
44
+ Rake::GemPackageTask.new(spec) do |pkg|
45
+ pkg.gem_spec = spec
46
+ end
47
+
48
+ desc "Install the gem"
49
+ task :install => [:package] do
50
+ sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
51
+ end
52
+
53
+ namespace :jruby do
54
+
55
+ desc "Run :package and install the resulting .gem with jruby"
56
+ task :install => :package do
57
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
58
+ end
59
+
60
+ end
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ TODO:
2
+ Fix LICENSE with your name
3
+ Fix Rakefile with your name and contact info
4
+ Add your code to lib/merb-haml.rb
5
+ Add your Merb rake tasks to lib/merb-haml/merbtasks.rb
data/lib/merb-haml.rb ADDED
@@ -0,0 +1,20 @@
1
+ # make sure we're running inside Merb
2
+ if defined?(Merb::Plugins)
3
+ require "haml"
4
+ require "merb-haml/template"
5
+ Merb::Plugins.add_rakefiles(File.join(File.dirname(__FILE__) / "merb-haml" / "merbtasks"))
6
+
7
+ Merb::BootLoader.after_app_loads do
8
+ if File.directory?(Merb.dir_for(:stylesheet) / "sass")
9
+ require "sass/plugin"
10
+ Sass::Plugin.options = Merb::Config[:sass] if Merb::Config[:sass]
11
+ end
12
+ end
13
+
14
+ # Hack because Haml uses symbolize_keys
15
+ class Hash
16
+ def symbolize_keys!
17
+ self
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ namespace :haml do
2
+ desc "Compiles all sass files into CSS"
3
+ task :compile_sass do
4
+ gem 'haml'
5
+ require 'sass'
6
+ puts "*** Updating stylesheets"
7
+ Sass::Plugin.options = Merb::Config[:sass] if Merb::Config[:sass]
8
+ Sass::Plugin.update_stylesheets
9
+ puts "*** Done"
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ module Merb::Template
2
+
3
+ class Haml
4
+
5
+ # Defines a method for calling a specific HAML template.
6
+ #
7
+ # ==== Parameters
8
+ # path<String>:: Path to the template file.
9
+ # name<~to_s>:: The name of the template method.
10
+ # mod<Class, Module>::
11
+ # The class or module wherein this method should be defined.
12
+ def self.compile_template(io, name, mod)
13
+ path = File.expand_path(io.path)
14
+ config = (Merb::Plugins.config[:haml] || {}).inject({}) do |c, (k, v)|
15
+ c[k.to_sym] = v
16
+ c
17
+ end.merge :filename => path
18
+ template = ::Haml::Engine.new(io.read, config)
19
+ template.def_method(mod, name)
20
+ name
21
+ end
22
+
23
+ module Mixin
24
+ # ==== Parameters
25
+ # string<String>:: The string to add to the HAML buffer.
26
+ # binding<Binding>::
27
+ # Not used by HAML, but is necessary to conform to the concat_*
28
+ # interface.
29
+ def concat_haml(string, binding)
30
+ haml_buffer.buffer << string
31
+ end
32
+
33
+ end
34
+ Merb::Template.register_extensions(self, %w[haml])
35
+ end
36
+ end
37
+
38
+ module Haml
39
+ class Engine
40
+
41
+ # ==== Parameters
42
+ # object<Class, Module>::
43
+ # The class or module wherein this method should be defined.
44
+ # name<~to_s>:: The name of the template method.
45
+ # *local_names:: Local names to define in the HAML template.
46
+ def def_method(object, name, *local_names)
47
+ method = object.is_a?(Module) ? :module_eval : :instance_eval
48
+
49
+ setup = "@_engine = 'haml'"
50
+
51
+ object.send(method, "def #{name}(_haml_locals = {}); #{setup}; #{precompiled_with_ambles(local_names)}; end",
52
+ @options[:filename], 0)
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,31 @@
1
+ class HamlController < Merb::Controller
2
+ self._template_root = File.dirname(__FILE__) / "views"
3
+ def index
4
+ render
5
+ end
6
+ end
7
+
8
+ class PartialHaml < HamlController
9
+ end
10
+
11
+ class HamlConfig < HamlController
12
+ end
13
+
14
+ class PartialIvars < HamlController
15
+ def index
16
+ @var1 = "Partial"
17
+ render
18
+ end
19
+ end
20
+
21
+ class CaptureHaml < HamlController
22
+ end
23
+
24
+ module Merb::ConcatHamlHelper
25
+ def concatter(&blk)
26
+ concat("<p>Concat</p>", blk.binding)
27
+ end
28
+ end
29
+
30
+ class ConcatHaml < HamlController
31
+ end
@@ -0,0 +1,3 @@
1
+ - x = capture do
2
+ %p Hello
3
+ = x
@@ -0,0 +1,2 @@
1
+ - concatter do
2
+ Hello
@@ -0,0 +1,2 @@
1
+ #foo
2
+ %foo
@@ -0,0 +1,2 @@
1
+ #foo
2
+ %p Hello
@@ -0,0 +1,2 @@
1
+ #foo
2
+ = partial :partial_haml
@@ -0,0 +1 @@
1
+ %p== #{@var1} #{@var2}
@@ -0,0 +1,3 @@
1
+ #foo
2
+ - @var2 = "HAML"
3
+ = partial :partial_haml
data/spec/haml_spec.rb ADDED
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "HAML" do
4
+ it "should be able to render HAML templates" do
5
+ c = dispatch_to(HamlController, :index)
6
+ c.body.should == ::Haml::Engine.new("#foo\n %p Hello").render
7
+ end
8
+
9
+ it "should be able to render HAML templates" do
10
+ c = dispatch_to(PartialHaml, :index)
11
+ c.body.should == ::Haml::Engine.new("#foo\n %p Partial").render
12
+ end
13
+
14
+ it "should use the haml configuration in Merb::Plugins.config" do
15
+ c = dispatch_to(HamlConfig, :index)
16
+ c.body.should == ::Haml::Engine.new("#foo\n %foo", :autoclose => ["foo"]).render
17
+ end
18
+
19
+ it "should be able to have ivars defined in both the controller and the parent template" do
20
+ c = dispatch_to(PartialIvars, :index)
21
+ c.body.should == ::Haml::Engine.new("#foo\n %p Partial HAML").render
22
+ end
23
+
24
+ it "should support capture" do
25
+ c = dispatch_to(CaptureHaml, :index)
26
+ c.body.should == "<p>Hello</p>\n"
27
+ end
28
+
29
+ it "should support concat" do
30
+ c = dispatch_to(ConcatHaml, :index)
31
+ c.body.should == "<p>Concat</p>"
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ $TESTING=true
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require "rubygems"
4
+ require "merb-core"
5
+ require "spec"
6
+
7
+ require "merb-haml"
8
+ require File.dirname(__FILE__) / "controllers" / "haml"
9
+
10
+ Merb::Plugins.config[:haml] = { "autoclose" => ["foo"] }
11
+ Merb.start :environment => 'test'
12
+
13
+ Spec::Runner.configure do |config|
14
+ config.include Merb::Test::RequestHelper
15
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thorero-haml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.4
5
+ platform: ruby
6
+ authors:
7
+ - Yehuda Katz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-02 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: haml
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.2
34
+ version:
35
+ description: Merb plugin that provides HAML support
36
+ email: ykatz@engineyard.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - LICENSE
44
+ - TODO
45
+ files:
46
+ - LICENSE
47
+ - README
48
+ - Rakefile
49
+ - TODO
50
+ - lib/merb-haml
51
+ - lib/merb-haml/merbtasks.rb
52
+ - lib/merb-haml/template.rb
53
+ - lib/merb-haml.rb
54
+ - spec/controllers
55
+ - spec/controllers/haml.rb
56
+ - spec/controllers/views
57
+ - spec/controllers/views/capture_haml
58
+ - spec/controllers/views/capture_haml/index.html.haml
59
+ - spec/controllers/views/concat_haml
60
+ - spec/controllers/views/concat_haml/index.html.haml
61
+ - spec/controllers/views/haml_config
62
+ - spec/controllers/views/haml_config/index.html.haml
63
+ - spec/controllers/views/haml_controller
64
+ - spec/controllers/views/haml_controller/index.html.haml
65
+ - spec/controllers/views/partial_haml
66
+ - spec/controllers/views/partial_haml/_partial_haml.html.haml
67
+ - spec/controllers/views/partial_haml/index.html.haml
68
+ - spec/controllers/views/partial_ivars
69
+ - spec/controllers/views/partial_ivars/_partial_haml.html.haml
70
+ - spec/controllers/views/partial_ivars/index.html.haml
71
+ - spec/haml_spec.rb
72
+ - spec/spec_helper.rb
73
+ has_rdoc: true
74
+ homepage: http://merbivore.com
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ requirements: []
93
+
94
+ rubyforge_project: thorero
95
+ rubygems_version: 1.2.0
96
+ signing_key:
97
+ specification_version: 2
98
+ summary: Merb plugin that provides HAML support
99
+ test_files: []
100
+