Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'html5-pre-rails-3' of https://github.com/gaelian/enki i…
…nto html5 Conflicts: app/helpers/application_helper.rb app/views/admin/comments/show.html.erb app/views/admin/dashboard/show.html.erb app/views/admin/pages/_page.html.erb app/views/admin/pages/new.html.erb app/views/admin/pages/show.html.erb app/views/admin/posts/_post.html.erb app/views/admin/posts/new.html.erb app/views/admin/posts/show.html.erb app/views/layouts/admin.html.erb app/views/layouts/application.html.erb config/environment.rb public/404.html public/422.html public/500.html spec/be_valid_html5.rb spec/be_valid_xhtml.rb spec/spec_helper.rb spec/support/be_valid_xhtml.rb spec/views/admin/comments/index.html.erb_spec.rb spec/views/admin/comments/show.html.erb_spec.rb spec/views/admin/dashboard/show.html.erb_spec.rb spec/views/admin/pages/index.html.erb_spec.rb spec/views/admin/pages/new.html.erb_spec.rb spec/views/admin/pages/show.html.erb_spec.rb spec/views/admin/posts/index.html.erb_spec.rb spec/views/admin/posts/new.html.erb_spec.rb spec/views/admin/posts/show.html.erb_spec.rb spec/views/admin/sessions/new.html.erb_spec.rb spec/views/admin/undo_items/index.html.erb_spec.rb spec/views/archives/index.html.erb_spec.rb spec/views/pages/show.html.erb_spec.rb spec/views/posts/index.html.erb_spec.rb spec/views/posts/show.html.erb_spec.rb
- Loading branch information
Showing
38 changed files
with
215 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<h1>Health</h1> | ||
|
||
<p><%= button_to("Throw exception", admin_health_path(:action => 'generate_exception')) %></p> | ||
<%= button_to("Throw exception", admin_health_path(:action => 'generate_exception')) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
<h1>Your pages</h1> | ||
|
||
<table cellspacing="0" cellpadding="0"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Created At</th> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<h1>Your tags</h1> | ||
|
||
<table cellspacing="0" cellpadding="0"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<cite><%= author_link(comment) %></cite> says: | ||
<br /> | ||
<br> | ||
<small class="commentmetadata"><a href="#comment-<%= comment.id %>" title=""><%= format_comment_date(comment.created_at) %></a></small> | ||
<p><%=raw comment.body_html %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require 'core_extensions/string' | ||
require 'core_extensions/object' | ||
require 'enki/html5_tags' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# TagHelper will output HTML tags as opposed to self-closed XHTML tags. | ||
# Shouldn't be needed for Rails >= version 3. | ||
module ActionView::Helpers::TagHelper | ||
def tag_with_html_patch(name, options = nil, open = true, escape = true) | ||
tag_without_html_patch(name, options, true, escape) | ||
end | ||
alias_method_chain :tag, :html_patch | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
# Paste me into spec_helper.rb, or save me somewhere else and require me in. | ||
require 'net/http' | ||
require 'digest/md5' | ||
require 'hpricot' | ||
|
||
class BeValidHtml5 | ||
|
||
def initialize(options) | ||
@fragment = options[:fragment] | ||
end | ||
|
||
# Assert that markup is valid according the W3C validator web service. | ||
# By default, it validates the contents of @response.body, which is set after calling | ||
# one of the get/post/etc helper methods. You can also pass it a string to be validated. | ||
# Validation errors, if any, will be included in the output. The input fragment and | ||
# response from the validator service will be cached in the $RAILS_ROOT/tmp directory to | ||
# minimize network calls. | ||
# | ||
# For example, if you have a FooController with an action Bar, put this in foo_controller_test.rb: | ||
# | ||
# def test_bar_valid_markup | ||
# get :bar | ||
# assert_valid_markup | ||
# end | ||
# | ||
MARKUP_VALIDATOR_HOST = ENV['MARKUP_VALIDATOR_HOST'] || 'validator.w3.org' | ||
MARKUP_VALIDATOR_PATH = ENV['MARKUP_VALIDATOR_PATH'] || '/check' | ||
CSS_VALIDATOR_HOST = ENV['CSS_VALIDATOR_HOST'] || 'jigsaw.w3.org' | ||
CSS_VALIDATOR_PATH = ENV['CSS_VALIDATOR_PATH'] || '/css-validator/validator' | ||
|
||
@@display_invalid_content = false | ||
cattr_accessor :display_invalid_content | ||
|
||
@@auto_validate = false | ||
cattr_accessor :auto_validate | ||
|
||
class_inheritable_accessor :auto_validate_excludes | ||
class_inheritable_accessor :auto_validate_includes | ||
|
||
|
||
def matches?(response) | ||
fn = response.rendered[:template].template_path | ||
fragment = response.body | ||
fragment = wrap_with_html5_header(fragment) if @fragment | ||
return true if validity_checks_disabled? | ||
base_filename = cache_resource('markup',fragment,fn) | ||
|
||
return false unless base_filename | ||
results_filename = base_filename + '-results.yml' | ||
|
||
begin | ||
response = File.open(results_filename) do |f| Marshal.load(f) end | ||
rescue | ||
response = http.start(MARKUP_VALIDATOR_HOST).post2(MARKUP_VALIDATOR_PATH, "fragment=#{CGI.escape(fragment)}&output=xml") | ||
File.open(results_filename, 'w+') do |f| Marshal.dump(response, f) end | ||
end | ||
markup_is_valid = response['x-w3c-validator-status'] == 'Valid' | ||
unless markup_is_valid | ||
fragment.split($/).each_with_index{|line, index| message << "#{'%04i' % (index+1)} : #{line}#{$/}"} if @@display_invalid_content | ||
@message = "Invalid markup:\n" | ||
@elements = Hpricot.XML(response.body).search("li.msg_err > span.msg") | ||
(@elements).each { |span| @message << CGI.unescapeHTML(span.inner_html) + "\n" } | ||
end | ||
if markup_is_valid | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def wrap_with_html5_header(fragment) | ||
ret = <<-EOS | ||
<!DOCTYPE html> | ||
<html dir="ltr" lang="en-US"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
#{fragment} | ||
</body> | ||
</html> | ||
EOS | ||
end | ||
|
||
def description | ||
"be valid html5" | ||
end | ||
|
||
def failure_message | ||
" expected html5 to be valid, but validation produced these errors:\n #{@message}" | ||
end | ||
|
||
def negative_failure_message | ||
" expected to not be valid, but was (missing validation?)" | ||
end | ||
|
||
private | ||
def validity_checks_disabled? | ||
ENV["NET"] != 'true' | ||
end | ||
|
||
def text_to_multipart(key,value) | ||
return "Content-Disposition: form-data; name=\"#{CGI::escape(key)}\"\r\n\r\n#{value}\r\n" | ||
end | ||
|
||
def file_to_multipart(key,filename,mime_type,content) | ||
return "Content-Disposition: form-data; name=\"#{CGI::escape(key)}\"; filename=\"#{filename}\"\r\n" + | ||
"Content-Transfer-Encoding: binary\r\nContent-Type: #{mime_type}\r\n\r\n#{content}\r\n" | ||
end | ||
|
||
def cache_resource(base,resource,fn) | ||
resource_md5 = Digest::MD5.hexdigest(resource).to_s | ||
file_md5 = nil | ||
|
||
output_dir = "#{RAILS_ROOT}/tmp/#{base}" | ||
base_filename = File.join(output_dir, fn) | ||
filename = base_filename | ||
|
||
parent_dir = File.dirname(filename) | ||
FileUtils.mkdir_p(parent_dir) unless File.exists?(parent_dir) | ||
|
||
File.open(filename, 'r') do |f| | ||
file_md5 = Digest::MD5.hexdigest(f.read(f.stat.size)).to_s | ||
end if File.exists?(filename) | ||
|
||
if file_md5 != resource_md5 | ||
Dir["#{base_filename}[^.]*"] .each {|f| File.delete(f)} | ||
File.open(filename, 'w+') do |f| f.write(resource); end | ||
end | ||
base_filename | ||
end | ||
|
||
def http | ||
if Module.constants.include?("ApplicationConfig") && ApplicationConfig.respond_to?(:proxy_config) | ||
Net::HTTP::Proxy(ApplicationConfig.proxy_config['host'], ApplicationConfig.proxy_config['port']) | ||
else | ||
Net::HTTP | ||
end | ||
end | ||
|
||
end | ||
|
||
def be_valid_html5 | ||
BeValidhtml5.new | ||
end | ||
|
||
def be_valid_html5_fragment | ||
BeValidHtml5.new(:fragment => true) | ||
end |
Oops, something went wrong.