hamlet 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +25 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/Rakefile +57 -0
- data/bin/hamletrb +7 -0
- data/extra/slim-mode.el +409 -0
- data/extra/test.hamlet +50 -0
- data/hamlet.gemspec +36 -0
- data/lib/hamlet.rb +7 -0
- data/lib/hamlet/engine.rb +3 -0
- data/lib/hamlet/parser.rb +147 -0
- data/lib/hamlet/template.rb +19 -0
- data/test/rails/Rakefile +7 -0
- data/test/rails/app/controllers/application_controller.rb +3 -0
- data/test/rails/app/controllers/parents_controller.rb +84 -0
- data/test/rails/app/controllers/slim_controller.rb +32 -0
- data/test/rails/app/helpers/application_helper.rb +2 -0
- data/test/rails/app/models/child.rb +3 -0
- data/test/rails/app/models/parent.rb +4 -0
- data/test/rails/app/views/layouts/application.html.slim +10 -0
- data/test/rails/app/views/parents/_form.html.slim +7 -0
- data/test/rails/app/views/parents/edit.html.slim +1 -0
- data/test/rails/app/views/parents/new.html.slim +1 -0
- data/test/rails/app/views/parents/show.html.slim +5 -0
- data/test/rails/app/views/slim/_partial.html.slim +1 -0
- data/test/rails/app/views/slim/content_for.html.slim +7 -0
- data/test/rails/app/views/slim/erb.html.erb +1 -0
- data/test/rails/app/views/slim/integers.html.slim +1 -0
- data/test/rails/app/views/slim/nil.html.slim +1 -0
- data/test/rails/app/views/slim/no_layout.html.slim +1 -0
- data/test/rails/app/views/slim/normal.html.slim +1 -0
- data/test/rails/app/views/slim/partial.html.slim +2 -0
- data/test/rails/app/views/slim/variables.html.slim +1 -0
- data/test/rails/config.ru +4 -0
- data/test/rails/config/application.rb +45 -0
- data/test/rails/config/boot.rb +10 -0
- data/test/rails/config/database.yml +4 -0
- data/test/rails/config/environment.rb +5 -0
- data/test/rails/config/environments/development.rb +26 -0
- data/test/rails/config/environments/production.rb +49 -0
- data/test/rails/config/environments/test.rb +35 -0
- data/test/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails/config/initializers/inflections.rb +10 -0
- data/test/rails/config/initializers/mime_types.rb +5 -0
- data/test/rails/config/initializers/secret_token.rb +7 -0
- data/test/rails/config/initializers/session_store.rb +8 -0
- data/test/rails/config/locales/en.yml +5 -0
- data/test/rails/config/routes.rb +60 -0
- data/test/rails/db/migrate/20101220223037_parents_and_children.rb +17 -0
- data/test/rails/script/rails +6 -0
- data/test/rails/test/helper.rb +10 -0
- data/test/rails/test/test_slim.rb +77 -0
- data/test/slim/helper.rb +200 -0
- data/test/slim/test_chain_manipulation.rb +42 -0
- data/test/slim/test_code_blocks.rb +68 -0
- data/test/slim/test_code_escaping.rb +53 -0
- data/test/slim/test_code_evaluation.rb +281 -0
- data/test/slim/test_code_output.rb +159 -0
- data/test/slim/test_code_structure.rb +95 -0
- data/test/slim/test_embedded_engines.rb +141 -0
- data/test/slim/test_html_escaping.rb +40 -0
- data/test/slim/test_html_structure.rb +438 -0
- data/test/slim/test_parser_errors.rb +107 -0
- data/test/slim/test_pretty.rb +75 -0
- data/test/slim/test_ruby_errors.rb +187 -0
- data/test/slim/test_sections.rb +90 -0
- data/test/slim/test_slim_template.rb +118 -0
- data/test/slim/test_text_interpolation.rb +78 -0
- data/test/slim/test_wrapper.rb +39 -0
- metadata +230 -0
@@ -0,0 +1 @@
|
|
1
|
+
p With a partial!
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Hello Erb!</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
p= @integer
|
@@ -0,0 +1 @@
|
|
1
|
+
p= @nil
|
@@ -0,0 +1 @@
|
|
1
|
+
h1 Hello Slim without a layout!
|
@@ -0,0 +1 @@
|
|
1
|
+
h1 Hello Slim!
|
@@ -0,0 +1 @@
|
|
1
|
+
h1= @hello
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'active_model/railtie'
|
4
|
+
require 'active_record/railtie'
|
5
|
+
require 'action_controller/railtie'
|
6
|
+
require 'action_view/railtie'
|
7
|
+
require 'action_mailer/railtie'
|
8
|
+
|
9
|
+
require 'slim'
|
10
|
+
require 'hamlet'
|
11
|
+
|
12
|
+
module Dummy
|
13
|
+
class Application < Rails::Application
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
15
|
+
# Application configuration should go into files in config/initializers
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
17
|
+
|
18
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
19
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
20
|
+
|
21
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
22
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
23
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
24
|
+
|
25
|
+
# Activate observers that should always be running.
|
26
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
27
|
+
|
28
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
29
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
30
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
31
|
+
|
32
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
33
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
34
|
+
# config.i18n.default_locale = :de
|
35
|
+
|
36
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
37
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
38
|
+
|
39
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
40
|
+
config.encoding = "utf-8"
|
41
|
+
|
42
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
43
|
+
config.filter_parameters += [:password]
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gemfile = File.expand_path('../../../../../../Gemfile', __FILE__)
|
3
|
+
|
4
|
+
if File.exist?(gemfile)
|
5
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.setup(:default, :integration)
|
8
|
+
end
|
9
|
+
|
10
|
+
$:.unshift File.expand_path('../../../../../../lib', __FILE__)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '123a9119fb14a410f485f9390286b33f2743b9d348246cf3e4434522078f77c202d7a1fb7e42666dd0844bcb10d0ff3d8b4ee087796269d4c574837948512dbf'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
resources :parents
|
6
|
+
|
7
|
+
# Sample of regular route:
|
8
|
+
# match 'products/:id' => 'catalog#view'
|
9
|
+
# Keep in mind you can assign values other than :controller and :action
|
10
|
+
|
11
|
+
# Sample of named route:
|
12
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
13
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
14
|
+
|
15
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
16
|
+
# resources :products
|
17
|
+
|
18
|
+
# Sample resource route with options:
|
19
|
+
# resources :products do
|
20
|
+
# member do
|
21
|
+
# get 'short'
|
22
|
+
# post 'toggle'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# collection do
|
26
|
+
# get 'sold'
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Sample resource route with sub-resources:
|
31
|
+
# resources :products do
|
32
|
+
# resources :comments, :sales
|
33
|
+
# resource :seller
|
34
|
+
# end
|
35
|
+
|
36
|
+
# Sample resource route with more complex sub-resources
|
37
|
+
# resources :products do
|
38
|
+
# resources :comments
|
39
|
+
# resources :sales do
|
40
|
+
# get 'recent', :on => :collection
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
|
44
|
+
# Sample resource route within a namespace:
|
45
|
+
# namespace :admin do
|
46
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
47
|
+
# # (app/controllers/admin/products_controller.rb)
|
48
|
+
# resources :products
|
49
|
+
# end
|
50
|
+
|
51
|
+
# You can have the root of your site routed with "root"
|
52
|
+
# just remember to delete public/index.html.
|
53
|
+
# root :to => "welcome#index"
|
54
|
+
|
55
|
+
# See how all your routes lay out with "rake routes"
|
56
|
+
|
57
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
58
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
59
|
+
match ':controller(/:action(/:id(.:format)))'
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ParentsAndChildren < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :parents do |t|
|
4
|
+
t.string :name
|
5
|
+
end
|
6
|
+
create_table :children do |t|
|
7
|
+
t.string :name
|
8
|
+
t.integer :parent_id
|
9
|
+
end
|
10
|
+
add_index :children, :parent_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :children
|
15
|
+
drop_table :parents
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../../config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Run any available migration
|
10
|
+
ActiveRecord::Migrator.migrate File.expand_path("../../db/migrate/", __FILE__)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class TestSlim < ActionController::IntegrationTest
|
4
|
+
test "normal view" do
|
5
|
+
get "slim/normal"
|
6
|
+
assert_response :success
|
7
|
+
assert_template ["slim/normal", "layouts/application"]
|
8
|
+
assert_html "<h1>Hello Slim!</h1>"
|
9
|
+
end
|
10
|
+
|
11
|
+
test "normal erb view" do
|
12
|
+
get "slim/erb"
|
13
|
+
assert_html "<h1>Hello Erb!</h1>"
|
14
|
+
end
|
15
|
+
|
16
|
+
test "view without a layout" do
|
17
|
+
get "slim/no_layout"
|
18
|
+
assert_template "slim/no_layout"
|
19
|
+
assert_html "<h1>Hello Slim without a layout!</h1>", :skip_layout => true
|
20
|
+
end
|
21
|
+
|
22
|
+
test "view with variables" do
|
23
|
+
get "slim/variables"
|
24
|
+
assert_html "<h1>Hello Slim with variables!</h1>"
|
25
|
+
end
|
26
|
+
|
27
|
+
test "partial view" do
|
28
|
+
get "slim/partial"
|
29
|
+
assert_html "<h1>Hello Slim!</h1><p>With a partial!</p>"
|
30
|
+
end
|
31
|
+
|
32
|
+
if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1 && Object.const_defined?(:Fiber)
|
33
|
+
puts 'Streaming test enabled'
|
34
|
+
test "streaming" do
|
35
|
+
get "slim/streaming"
|
36
|
+
output = "2f\r\n<!DOCTYPE html><html><head><title>Dummy</title>\r\nd\r\n</head><body>\r\n17\r\nHeading set from a view\r\n15\r\n<div class=\"content\">\r\n53\r\n<p>Page content</p><h1><p>Hello Streaming!</p></h1><h2><p>Hello Streaming!</p></h2>\r\n14\r\n</div></body></html>\r\n0\r\n\r\n"
|
37
|
+
assert_equal output, @response.body
|
38
|
+
end
|
39
|
+
else
|
40
|
+
puts 'Streaming test disabled'
|
41
|
+
end
|
42
|
+
|
43
|
+
test "render integers" do
|
44
|
+
get "slim/integers"
|
45
|
+
assert_html "<p>1337</p>"
|
46
|
+
end
|
47
|
+
|
48
|
+
test "render nil" do
|
49
|
+
get "slim/nil"
|
50
|
+
assert_html "<p></p>"
|
51
|
+
end
|
52
|
+
|
53
|
+
test "content_for" do
|
54
|
+
get "slim/content_for"
|
55
|
+
assert_html "<p>Page content</p><h1><p>Hello Slim!</p></h1><h2><p>Hello Slim!</p></h2>", :heading => 'Heading set from a view'
|
56
|
+
end
|
57
|
+
|
58
|
+
test "nested_attributes_form" do
|
59
|
+
post "parents", 'parent[name]' => "p1", 'parent[children_attributes][0][name]' => "c1"
|
60
|
+
get "parents/1/edit"
|
61
|
+
|
62
|
+
assert_html '<form accept-charset="UTF-8" action="/parents/1" class="edit_parent" enctype="multipart/form-data" id="edit_parent_1" method="post">'+
|
63
|
+
'<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" />'+
|
64
|
+
'</div><h1>Parent</h1><input id="parent_name" name="parent[name]" size="30" type="text" value="p1" />'+
|
65
|
+
'<h2>Children</h2>'+
|
66
|
+
'<ul><li><input id="parent_children_attributes_0_name" name="parent[children_attributes][0][name]" size="30" type="text" value="c1" /></li>'+
|
67
|
+
'<input id="parent_children_attributes_0_id" name="parent[children_attributes][0][id]" type="hidden" value="1" /></ul>'+
|
68
|
+
'</form>'
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
|
73
|
+
def assert_html(expected, options = {})
|
74
|
+
expected = "<!DOCTYPE html><html><head><title>Dummy</title></head><body>#{options[:heading]}<div class=\"content\">#{expected}</div></body></html>" unless options[:skip_layout]
|
75
|
+
assert_equal expected, @response.body
|
76
|
+
end
|
77
|
+
end
|