Skip to content
Browse files

Tagging version 1.7.2.

git-svn-id: svn://hamptoncatlin.com/haml/tags/rel_1-7-2@627 7063305b-7217-0410-af8c-cdc13e5119b9
  • Loading branch information...
1 parent f3ff721 commit d62b796a459ddb5cda1daf9331d8b706abdae8d6 @nex3 nex3 committed
View
27 README
@@ -11,11 +11,18 @@ and providing elegant, easily understandable, and powerful syntax.
== Using
-There are two ways to use Haml and Sass.
-The easiest is as a Rails plugin:
-Simply type <tt>./script/plugin install http://hamptoncatlin.com/haml/stable</tt>
+There are several ways to use Haml and Sass.
+They can be used as a plugins for Rails or Merb,
+or embedded on their own in other applications.
+The first step of all of these is to install the Haml gem:
+
+ gem install haml
+
+To install Haml and Sass as a Rails plugin,
+just run <tt>haml --rails path/to/rails/app</tt>
and both Haml and Sass will be installed.
-Views with the <tt>.haml</tt> extension will automatically use Haml.
+Views with the <tt>.haml</tt> (or <tt>.html.haml</tt> for edge)
+extension will automatically use Haml.
Sass is a little more complicated;
<tt>.sass</tt> files should be placed in public/stylesheets/sass,
where they'll be automatically compiled
@@ -23,6 +30,18 @@ to corresponding CSS files in public/stylesheets when needed
(the Sass template directory is customizable...
see the Sass module docs for details).
+For Merb, <tt>.html.haml</tt> views will work without any further modification.
+To enable Sass, you also need to add it add a dependency.
+To do so, just add
+
+ dependency "haml"
+
+to config/dependencies.rb.
+Then it'll work just like it does in Rails.
+
+To use Haml and Sass programatically,
+check out the RDocs for the Haml and Sass modules.
+
== Formatting
=== Haml
View
6 Rakefile
@@ -67,6 +67,7 @@ unless ARGV[0] == 'benchmark'
It was originally envisioned as a plugin for Ruby on Rails,
but it can function as a stand-alone templating engine.
END
+ #'
readmes = FileList.new('*') do |list|
list.exclude(/[a-z]/)
@@ -74,6 +75,7 @@ unless ARGV[0] == 'benchmark'
end.to_a
spec.executables = ['haml', 'html2haml', 'sass']
spec.files = FileList['lib/**/*', 'bin/*', 'test/**/*', 'Rakefile', 'init.rb'].to_a + readmes
+ spec.autorequire = ['haml', 'sass']
spec.homepage = 'http://haml.hamptoncatlin.com/'
spec.has_rdoc = true
spec.extra_rdoc_files = readmes
@@ -93,6 +95,10 @@ unless ARGV[0] == 'benchmark'
pkg.need_tar_bz2 = true
end
+ task :install => [:package] do
+ sh %{gem install --no-ri pkg/haml-#{File.read('VERSION').strip}}
+ end
+
# ----- Documentation -----
require 'rake/rdoctask'
View
2 VERSION
@@ -1 +1 @@
-1.7.1
+1.7.2
View
41 lib/haml.rb
@@ -25,22 +25,31 @@
#
# Haml can be used in two ways:
# as a plugin for Ruby on Rails,
-# and as a standalong Ruby module.
+# and as a standalone Ruby module.
#
-# === Rails
+# Sass can be used in several ways:
+# As a template engine for Ruby on Rails or Merb,
+# or as a standalone engine.
+# The first step for all of these is to install the Haml gem:
+#
+# gem install haml
+#
+# To enable it as a Rails plugin,
+# then run
#
-# Haml is most commonly used as a plugin.
-# It can be installed as a plugin using the Rails plugin installer:
+# haml --rails path/to/rails/app
#
-# ./script/plugin install http://svn.hamptoncatlin.com/haml/tags/stable
+# Haml is enabled in Merb by default,
+# so Merb users don't have to do anything more.
#
# Once it's installed, all view files with the ".haml" extension
+# (or ".html.haml" for Merb or edge Rails)
# will be compiled using Haml.
#
# You can access instance variables in Haml templates
# the same way you do in ERb templates.
# Helper methods are also available in Haml templates.
-# For example:
+# For example (this example uses Rails, but the principle for Merb is the same):
#
# # file: app/controllers/movies_controller.rb
#
@@ -50,7 +59,7 @@
# end
# end
#
-# # file: app/views/movies/index.haml
+# -# file: app/views/movies/index.haml
#
# #content
# .title
@@ -152,7 +161,7 @@
# @user = CrazyUser.find(15)
# end
#
-# # file: app/views/users/show.haml
+# -# file: app/views/users/show.haml
#
# %div[@user]
# %bar[290]/
@@ -357,7 +366,7 @@
#
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
#
-# If you're not using the UTF-8 characterset for your document,
+# If you're not using the UTF-8 character set for your document,
# you can specify which encoding should appear
# in the XML prolog in a similar way.
# For example:
@@ -374,16 +383,16 @@
# wraps all text after it in an HTML comment.
# For example:
#
-# %billabong
-# / This is the billabong element
-# I like billabongs!
+# %peanutbutterjelly
+# / This is the peanutbutterjelly element
+# I like sandwiches!
#
# is compiled to:
#
-# <billabong>
-# <!-- This is the billabong element -->
-# I like billabongs!
-# </billabong>
+# <peanutbutterjelly>
+# <!-- This is the peanutbutterjelly element -->
+# I like sandwiches!
+# </peanutbutterjelly>
#
# The forward slash can also wrap indented sections of code. For example:
#
View
4 lib/haml/engine.rb
@@ -123,7 +123,7 @@ def initialize(template, l_options = {})
:suppress_eval => false,
:attr_wrapper => "'",
:locals => {},
- :autoclose => ['meta', 'img', 'link', 'br', 'hr'],
+ :autoclose => ['meta', 'img', 'link', 'br', 'hr', 'input', 'area'],
:filters => {
'sass' => Sass::Engine,
'plain' => Haml::Filters::Plain,
@@ -228,7 +228,7 @@ def #{method_name}(_haml_local_assigns)
old_uline = nil
(@template + "\n-#\n-#").each_with_index do |line, index|
spaces, tabs = count_soft_tabs(line)
- uline = line.lstrip[0...-1]
+ uline = line.lstrip.chomp
line = uline.rstrip
if !line.empty?
View
12 lib/haml/helpers/action_view_mods.rb
@@ -1,14 +1,4 @@
-begin
- require 'rubygems'
- require 'active_support'
- require 'action_controller'
- require 'action_view'
- action_view_included = true
-rescue LoadError
- action_view_included = false
-end
-
-if action_view_included
+if defined?(ActionView) and not defined?(Merb::Plugins)
module ActionView
class Base # :nodoc:
def render_with_haml(*args, &block)
View
61 lib/sass.rb
@@ -20,19 +20,29 @@
#
# == Using Sass
#
-# Sass can be used in two ways:
-# As a plugin for Ruby on Rails
-# and as a standalone parser.
+# Sass can be used in several ways:
+# As a plugin for Ruby on Rails or Merb,
+# or as a standalone parser.
# Sass is bundled with Haml,
# so if the Haml plugin or RubyGem is installed,
# Sass will already be installed as a plugin or gem, respectively.
+# The first step for all of these is to install the Haml gem:
#
-# To install Haml and Sass as a Ruby on Rails plugin,
-# use the normal Rails plugin installer:
+# gem install haml
+#
+# To enable it as a Rails plugin,
+# then run
+#
+# haml --rails path/to/rails/app
+#
+# To enable Sass in Merb,
+# add
+#
+# dependency "haml"
#
-# ./script/plugin install http://svn.hamptoncatlin.com/haml/tags/stable
+# to config/dependencies.rb.
#
-# Sass templates in Rails don't quite function in the same way as views,
+# Sass templates in Rails and Merb don't quite function in the same way as views,
# because they don't contain dynamic content,
# and so only need to be compiled when the template file has been updated.
# By default (see options, below),
@@ -41,11 +51,8 @@
# For instance, public/stylesheets/sass/main.sass would be compiled to public/stylesheets/main.css.
#
# Using Sass in Ruby code is very simple.
-# First install the Haml/Sass RubyGem:
-#
-# gem install haml
-#
-# Then you can use it by including the "sass" gem
+# After installing the Haml gem,
+# you can use it by running <tt>require "sass"</tt>
# and using Sass::Engine like so:
#
# engine = Sass::Engine.new("#main\n :background-color #0000ff")
@@ -394,7 +401,7 @@
# but all constants in that file are made available in the current file.
#
# Sass looks for other Sass files in the working directory,
-# and the Sass file directory under Rails.
+# and the Sass file directory under Rails or Merb.
# Additional search directories may be specified
# using the :load_paths option (see below).
#
@@ -562,7 +569,7 @@
# time a controller is accessed,
# as opposed to only when the template has been modified.
# Defaults to false.
-# Only has meaning within Ruby on Rails.
+# Only has meaning within Ruby on Rails or Merb.
#
# [<tt>:always_check</tt>] Whether a Sass template should be checked for updates every
# time a controller is accessed,
@@ -573,24 +580,34 @@
# true otherwise.
# Only has meaning within Ruby on Rails.
#
+# [<tt>:full_exception</tt>] Whether an error in the Sass code
+# should cause Sass to provide a detailed description.
+# If set to true, the specific error will be displayed
+# along with a line number and source snippet.
+# Otherwise, a simple uninformative error message will be displayed.
+# Defaults to false in production mode, true otherwise.
+# Only has meaning within Ruby on Rails or Merb.
+#
# [<tt>:template_location</tt>] The directory where Sass templates should be read from.
-# Defaults to <tt>RAILS_ROOT + "/public/stylesheets/sass"</tt>.
-# Only has meaning within Ruby on Rails.
+# Defaults to <tt>RAILS_ROOT + "/public/stylesheets/sass"</tt>
+# or <tt>MERB_ROOT + "/public/stylesheets/sass"</tt>.
+# Only has meaning within Ruby on Rails or Merb.
#
# [<tt>:css_location</tt>] The directory where CSS output should be written to.
-# Defaults to <tt>RAILS_ROOT + "/public/stylesheets"</tt>.
-# Only has meaning within Ruby on Rails.
+# Defaults to <tt>RAILS_ROOT + "/public/stylesheets"</tt>
+# or <tt>MERB_ROOT + "/public/stylesheets"</tt>.
+# Only has meaning within Ruby on Rails or Merb.
#
# [<tt>:filename</tt>] The filename of the file being rendered.
# This is used solely for reporting errors,
-# and is automatically set when using Rails.
+# and is automatically set when using Rails or Merb.
#
# [<tt>:load_paths</tt>] An array of filesystem paths which should be searched
# for Sass templates imported with the "@import" directive.
-# This defaults to the working directory and, in Rails,
-# whatever <tt>:template_location</tt> is
-# (by default <tt>RAILS_ROOT + "/public/stylesheets/sass"</tt>).
+# This defaults to the working directory and, in Rails or Merb,
+# whatever <tt>:template_location</tt> is.
#
module Sass; end
require 'sass/engine'
+require 'sass/plugin' if defined?(Merb::Plugins)
View
2 lib/sass/engine.rb
@@ -292,7 +292,7 @@ def import(files)
engine = nil
filename = find_file_to_import(filename)
if filename =~ /\.css$/
- nodes << Tree::ValueNode.new("@import #{filename}", @options[:style])
+ nodes << Tree::ValueNode.new("@import url(#{filename});", @options[:style])
else
File.open(filename) do |file|
new_options = @options.dup
View
36 lib/sass/plugin.rb
@@ -1,21 +1,17 @@
require 'sass/engine'
-require 'rubygems'
-require 'action_controller'
-
-RAILS_ROOT = '. 'unless self.class.const_defined?('RAILS_ROOT')
-RAILS_ENV = 'production' unless self.class.const_defined?('RAILS_ENV')
module Sass
- # This module contains methods that ActionController calls
- # to automatically update Sass templates that need updating.
- # It wasn't designed to be used outside of the context of ActionController.
+ # This module contains methods to aid in using Sass
+ # as a stylesheet-rendering plugin for various systems.
+ # Currently Rails/ActionController and Merb are supported out of the box.
module Plugin
class << self
@@options = {
- :template_location => RAILS_ROOT + '/public/stylesheets/sass',
- :css_location => RAILS_ROOT + '/public/stylesheets',
+ :template_location => './public/stylesheets/sass',
+ :css_location => './public/stylesheets',
:always_update => false,
- :always_check => RAILS_ENV != "production"
+ :always_check => true,
+ :full_exception => true
}
# Gets various options for Sass. See README for details.
@@ -54,7 +50,7 @@ def update_stylesheets
begin
result = engine.render
rescue Exception => e
- if RAILS_ENV != "production"
+ if options[:full_exception]
e_string = "#{e.class}: #{e.message}"
if e.is_a? Sass::SyntaxError
@@ -111,17 +107,5 @@ def stylesheet_needs_update?(name)
end
end
-# This module refers to the ActionController module that's part of Ruby on Rails.
-# Sass can be used as an alternate templating engine for Rails,
-# and includes some modifications to make this more doable.
-# The documentation can be found
-# here[http://rubyonrails.org/api/classes/ActionController/Base.html].
-module ActionController
- class Base # :nodoc:
- alias_method :sass_old_process, :process
- def process(*args)
- Sass::Plugin.update_stylesheets if Sass::Plugin.options[:always_update] || Sass::Plugin.options[:always_check]
- sass_old_process(*args)
- end
- end
-end
+require 'sass/plugin/rails' if defined?(ActionController)
+require 'sass/plugin/merb' if defined?(Merb::Plugins)
View
20 lib/sass/plugin/merb.rb
@@ -0,0 +1,20 @@
+unless defined?(Sass::MERB_LOADED)
+ Sass::MERB_LOADED = true
+
+ Sass::Plugin.options.merge!(:template_location => MERB_ROOT + '/public/stylesheets/sass',
+ :css_location => MERB_ROOT + '/public/stylesheets',
+ :always_check => MERB_ENV != "production",
+ :full_exception => MERB_ENV != "production")
+ config = Merb::Plugins.config[:sass] || Merb::Plugins.config["sass"] || {}
+ config.symbolize_keys!
+ Sass::Plugin.options.merge!(config)
+
+ class MerbHandler # :nodoc:
+ def process_with_sass(request, response)
+ Sass::Plugin.update_stylesheets if Sass::Plugin.options[:always_update] || Sass::Plugin.options[:always_check]
+ process_without_sass(request, response)
+ end
+ alias_method :process_without_sass, :process
+ alias_method :process, :process_with_sass
+ end
+end
View
18 lib/sass/plugin/rails.rb
@@ -0,0 +1,18 @@
+unless defined?(Sass::RAILS_LOADED)
+ Sass::RAILS_LOADED = true
+
+ Sass::Plugin.options.merge!(:template_location => RAILS_ROOT + '/public/stylesheets/sass',
+ :css_location => RAILS_ROOT + '/public/stylesheets',
+ :always_check => RAILS_ENV != "production",
+ :full_exception => RAILS_ENV != "production")
+
+ module ActionController # :nodoc:
+ class Base # :nodoc:
+ alias_method :sass_old_process, :process
+ def process(*args)
+ Sass::Plugin.update_stylesheets if Sass::Plugin.options[:always_update] || Sass::Plugin.options[:always_check]
+ sass_old_process(*args)
+ end
+ end
+ end
+end
View
9 test/benchmark.rb
@@ -1,9 +1,12 @@
-require File.dirname(__FILE__) + '/../lib/haml'
-require 'haml/template'
-require 'sass/engine'
require 'rubygems'
require 'active_support'
+require 'action_controller'
require 'action_view'
+
+require File.dirname(__FILE__) + '/../lib/haml'
+require 'haml/template'
+require 'sass/engine'
+
require 'benchmark'
require 'stringio'
View
5 test/haml/engine_test.rb
@@ -1,5 +1,10 @@
#!/usr/bin/env ruby
+require 'rubygems'
+require 'active_support'
+require 'action_controller'
+require 'action_view'
+
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/haml'
require 'haml/engine'
View
24 test/haml/helper_test.rb
@@ -1,5 +1,10 @@
#!/usr/bin/env ruby
+require 'rubygems'
+require 'active_support'
+require 'action_controller'
+require 'action_view'
+
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/haml'
require 'haml/template'
@@ -72,24 +77,7 @@ def test_helpers_dont_leak
def test_action_view_included
assert(Haml::Helpers.action_view?)
end
-
- def test_action_view_not_included
- #This is for 100% rcov, rather than any real testing purposes.
- Kernel.module_eval do
- alias_method :old_require, :require
- def require(string)
- raise LoadError if string == "action_view"
- old_require string
- end
- end
-
- load File.dirname(__FILE__) + '/../../lib/haml/helpers/action_view_mods.rb'
-
- Kernel.module_eval do
- alias_method :require, :old_require
- end
- end
-
+
def test_form_tag
result = render("- form_tag 'foo' do\n %p bar\n %strong baz", :action_view)
should_be = "<form action=\"foo\" method=\"post\">\n <p>bar</p>\n <strong>baz</strong>\n</form>\n"
View
1 test/haml/runner.rb
@@ -1,5 +1,6 @@
require 'rubygems'
require 'active_support'
+require 'action_controller'
require 'action_view'
require '../../lib/haml/template'
require 'fileutils'
View
8 test/profile.rb
@@ -1,8 +1,10 @@
-require File.dirname(__FILE__) + '/../lib/haml'
-require 'haml/template'
require 'rubygems'
require 'active_support'
+require 'action_controller'
require 'action_view'
+
+require File.dirname(__FILE__) + '/../lib/haml'
+require 'haml/template'
require 'profiler'
require 'stringio'
@@ -46,7 +48,7 @@ def initialize(base = File.join(File.dirname(__FILE__), 'haml', 'templates'))
# automatically look for a haml template.
#
# Returns the results of the profiling as a string.
- def profile(runs = 100, template_name = 'standard')
+ def profile(runs = 100, template_name = 'standard')
AbstractProfiler.profile(runs) { @base.render template_name }
end
end
View
57 test/sass/plugin_test.rb
@@ -1,9 +1,14 @@
#!/usr/bin/env ruby
-RAILS_ENV = 'testing'
+MERB_ENV = RAILS_ENV = 'testing'
+RAILS_ROOT = '.'
+
require 'test/unit'
require 'fileutils'
require File.dirname(__FILE__) + '/../../lib/sass'
+require 'rubygems'
+
+require 'action_controller'
require 'sass/plugin'
class SassPluginTest < Test::Unit::TestCase
@@ -14,14 +19,7 @@ class SassPluginTest < Test::Unit::TestCase
def setup
FileUtils.mkdir File.dirname(__FILE__) + '/tmp'
- Sass::Plugin.options = {
- :template_location => File.dirname(__FILE__) + '/templates',
- :css_location => File.dirname(__FILE__) + '/tmp',
- :style => :compact,
- :load_paths => [File.dirname(__FILE__) + '/results'],
- }
- Sass::Plugin.options[:always_update] = true
-
+ set_plugin_opts
Sass::Plugin.update_stylesheets
end
@@ -40,7 +38,7 @@ def test_no_update
assert !Sass::Plugin.stylesheet_needs_update?('basic')
end
- def test_exception_handling
+ def test_full_exception_handling
File.delete(tempfile_loc('bork'))
Sass::Plugin.update_stylesheets
File.open(tempfile_loc('bork')) do |file|
@@ -49,18 +47,18 @@ def test_exception_handling
File.delete(tempfile_loc('bork'))
end
- def test_production_exception_handling
- Sass.const_set('RAILS_ENV', 'production')
+ def test_nonfull_exception_handling
+ Sass::Plugin.options[:full_exception] = false
File.delete(tempfile_loc('bork'))
Sass::Plugin.update_stylesheets
assert_equal("/* Internal stylesheet error */", File.read(tempfile_loc('bork')))
File.delete(tempfile_loc('bork'))
- Sass::Plugin.const_set('RAILS_ENV', 'testing')
+ Sass::Plugin.options[:full_exception] = true
end
- def test_controller_process
+ def test_rails_update
File.delete(tempfile_loc('basic'))
assert Sass::Plugin.stylesheet_needs_update?('basic')
@@ -69,6 +67,27 @@ def test_controller_process
assert !Sass::Plugin.stylesheet_needs_update?('basic')
end
+ def test_merb_update
+ begin
+ require 'merb'
+ rescue LoadError
+ puts "\nmerb couldn't be loaded, skipping a test"
+ return
+ end
+
+ require 'sass/plugin/merb'
+ MerbHandler.send(:define_method, :process_without_sass) { |*args| }
+ set_plugin_opts
+
+ File.delete(tempfile_loc('basic'))
+ assert Sass::Plugin.stylesheet_needs_update?('basic')
+
+ MerbHandler.new('.').process nil, nil
+
+ assert !Sass::Plugin.stylesheet_needs_update?('basic')
+ end
+
+
private
def assert_renders_correctly(name)
@@ -85,6 +104,16 @@ def tempfile_loc(name)
def result_loc(name)
File.dirname(__FILE__) + "/results/#{name}.css"
end
+
+ def set_plugin_opts
+ Sass::Plugin.options = {
+ :template_location => File.dirname(__FILE__) + '/templates',
+ :css_location => File.dirname(__FILE__) + '/tmp',
+ :style => :compact,
+ :load_paths => [File.dirname(__FILE__) + '/results'],
+ :always_update => true,
+ }
+ end
end
module Sass::Plugin
View
4 test/sass/results/import.css
@@ -22,6 +22,6 @@ body { font: Arial; background: blue; }
#content.user.show #container.top #column.right { width: 600px; }
#content.user.show #container.bottom { background: brown; }
-@import basic.css
-@import ../results/complex.css
+@import url(basic.css);
+@import url(../results/complex.css);
nonimported { myconst: hello; otherconst: goodbye; }

0 comments on commit d62b796

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