Permalink
Browse files

fixed tests and now added a new url feature

  • Loading branch information...
1 parent ff7a41c commit b508019dc42cfd182ab1f8195ea9185d88a13cd6 @twilson63 committed Dec 4, 2010
View
@@ -1,2 +1,3 @@
---
+BUNDLE_DISABLE_SHARED_GEMS: "1"
BUNDLE_WITHOUT: ""
View
@@ -0,0 +1 @@
+--color
View
@@ -1,10 +1,16 @@
source :gemcutter
gem 'thin'
-gem 'sinatra', '1.0.0'
+gem 'sinatra', '1.1.0'
gem 'hpricot'
-gem 'haml', '3.0.11'
+gem 'haml', '3.0.24'
gem 'json'
gem 'builder'
gem 'erubis'
-gem 'ruby_parser'
+gem 'ruby_parser'
+gem 'crack'
+
+group :test do
+ gem 'rspec'
+ gem 'rack-test'
+end
View
@@ -2,34 +2,49 @@ GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
- builder (2.1.2)
+ builder (3.0.0)
daemons (1.1.0)
+ diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
eventmachine (0.12.10)
- haml (3.0.11)
- hpricot (0.8.2)
+ haml (3.0.24)
+ hpricot (0.8.3)
json (1.4.6)
rack (1.2.1)
- ruby_parser (2.0.4)
- sexp_processor (~> 3.0)
- sexp_processor (3.0.4)
- sinatra (1.0)
+ rack-test (0.5.6)
rack (>= 1.0)
+ rspec (2.2.0)
+ rspec-core (~> 2.2)
+ rspec-expectations (~> 2.2)
+ rspec-mocks (~> 2.2)
+ rspec-core (2.2.1)
+ rspec-expectations (2.2.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.2.0)
+ ruby_parser (2.0.5)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.0.5)
+ sinatra (1.1.0)
+ rack (~> 1.1)
+ tilt (~> 1.1)
thin (1.2.7)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
+ tilt (1.1)
PLATFORMS
ruby
DEPENDENCIES
builder
erubis
- haml (= 3.0.11)
+ haml (= 3.0.24)
hpricot
json
+ rack-test
+ rspec
ruby_parser
- sinatra (= 1.0.0)
+ sinatra (= 1.1.0)
thin
View
@@ -0,0 +1,84 @@
+# html2haml.heroku.com
+
+html2haml is a sinatra web application that allows you to convert
+html 2 haml.
+
+It is currently using haml 3.0.24!
+
+## Features
+
+* html text to haml text
+
+ Copy your html in the html text area and click on convert
+ and html2haml will convert it to haml in the text box below.
+
+* url to haml
+
+ Enter a url to a web site and click submit
+ html2haml will download the page and convert it to haml
+ in the haml text area below
+
+* send you html via web service
+
+ - XML
+
+ curl -XPOST -d "<page><html><h1>Hello World</h1></html></page>" http://html2haml.heroku.com/api.xml
+
+ - JSON
+
+ curl -
+## Requirements for Development
+
+* Ruby 1.8.7
+* Bundler
+
+## Development
+
+ git clone git://github.com/twilson63/html2haml.git
+
+ bundle install
+
+ # run tests
+ rake
+
+ # run application
+ rackup
+
+ # open browser to http://localhost:9292
+
+## Having problems
+
+Please post an issue in the issues
+
+## How to contribute
+
+Interested in adding a new feature to the application? Awesome!
+
+* First clone the repository
+* Write a test for your feature in the spec folder using rspec
+* Write your new feature
+* Once your code is passing and re-factored send a pull request
+
+## LICENSE
+
+The MIT License
+
+Copyright (c) 2008 Jack Russell Software Company
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -1,22 +0,0 @@
-h1. Html2Haml
-
-h2. WebSite
-
-"http://html2haml.heroku.com":http://html2haml.heroku.com
-
-Html2Haml is a simple sinatra app that converts html markup to haml.
-
-You simply copy your html in the first box and click convert, then see the results in the haml box below.
-
-Check it out.
-
-This also demonstrates using Cucumber and Webrat with Sinatra. And doing BDD with technologies.
-
-h2. Api
-
-You can also run the convert via a RestClient or Curl Client, by posting your html in the page_html parameter.
-
-Coming Soon
-
-h2. License
-
View
@@ -0,0 +1,18 @@
+require 'rubygems'
+#require 'bundler'
+
+#Bundler.setup :default, :test, :development
+
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+end
+
+# RSpec::Core::RakeTask.new(:rcov) do |spec|
+# spec.pattern = 'spec/**/*_spec.rb'
+# spec.rcov = true
+# end
+
+#task :spec => :check_dependencies
+task :default => :spec
View
@@ -1,19 +1,9 @@
-begin
- # Require the preresolved locked set of gems.
- require File.expand_path('../.bundle/environment', __FILE__)
-rescue LoadError
- # Fallback on doing the resolve at runtime.
- require "rubygems"
- require "bundler"
- Bundler.setup
-end
-
-require 'sinatra'
+require "rubygems"
+#require "bundler"
+#Bundler.require
+require 'html2haml.rb'
set :environment, :production
disable :run
-
-require 'html2haml.rb'
-
run Sinatra::Application
View
@@ -1 +0,0 @@
-default: -r features/support/env.rb -r features/step_definitions features -t current -s
@@ -1,23 +0,0 @@
-Feature: Convert Html 2 Haml
- In order to convert html 2 haml
- As a guest
- I want to copy a snippet of html into a text box and press covert to haml and display the haml in a results text area
-
- @working
- Scenario: Copy Html and Convert to Haml
- Given I go to /
- And I fill in "Html" with "<h1>Hello World</h1>"
- When I press "Convert"
- Then I should see "%h1"
-
- @working
- Scenario: Post Html via JSON and Convert to Haml
- Given I have a page object with "<h1>Hello World</h1>" in the html attribute
- When I post the page object to /json
- Then I should see "{page: { html: "<h1>Hello World</h1>", haml: "\n%h1\n Hello World" }}"
-
- @current
- Scenario: Error with inserting TextArea in html
- Given I have a page object with "<textarea>Hello World</textarea><b>outside</b>" in the html attribute
- When I press "Convert"
- Then I should see "<textarea>Hello World</textarea><b>outside</b>"
@@ -1,12 +0,0 @@
-Given /^I have a page object with "([^\"]*)" in the html attribute$/ do |html|
- @page = {:page => {:html => html}}
-
-end
-
-When /^I post the page object to \/json$/ do
- puts post("/json", :page_html => "Hello").body
-end
-
-Then /^I should see "([^\"]*)"<h1>Hello World<\/h1>"([^\"]*)"\\n%h1\\n Hello World"([^\"]*)"$/ do |arg1, arg2, arg3|
-
-end
@@ -1,20 +0,0 @@
-When /^I go to (.+)$/ do |page_name|
- visit page_name
-end
-
-When /^I press "([^\"]*)"$/ do |button|
- click_button(button)
-end
-
-When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
- fill_in(field, :with => value)
-end
-
-Then /^I should see "([^\"]*)"$/ do |text|
- response.should contain(text)
-end
-
-And /^Save and Open Page$/ do
- save_and_open_page
-end
-
@@ -1,22 +0,0 @@
-require 'sinatra'
-# Sinatra
-app_file = File.join(File.dirname(__FILE__), *%w[.. .. html2haml.rb])
-require app_file
-# Force the application name because polyglot breaks the auto-detection logic.
-Sinatra::Application.app_file = app_file
-
-# RSpec matchers
-require 'spec/expectations'
-
-# Webrat
-require 'webrat'
-Webrat.configure do |config|
- config.mode = :sinatra
-end
-
-World do
- session = Webrat::SinatraSession.new
- session.extend(Webrat::Matchers)
- session.extend(Webrat::HaveTagMatcher)
- session
-end
View
@@ -1,48 +1,44 @@
+require "sinatra"
require "haml"
require "haml/html"
require "json"
+require "net/http"
+require "open-uri"
+require "crack"
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
-get "/" do
+get "/*" do
haml :index
end
+post '/url' do
+ @html = open("http://#{params[:q]}") { |f| f.read }
+ @haml = convert(@html)
+ haml :index
-post "/*" do
- puts params
- if params["page"]
- @html = params["page"]["html"]
- @haml = convert(@html)
- if params[:splat].include?("json")
- {:page => {:html => @html, :haml => @haml}}.to_json
- elsif params[:splat].include?("xml")
- to_xml
- else
- haml :index
- end
- end
end
-def convert(html)
- Haml::HTML.new(@html, :erb => true, :xhtml => true).render
+post '/api.json' do
+ puts request.body.to_s
+ @res = Crack::JSON.parse(request.body)
+ @html = @res[:page][:html]
+ @haml = convert(@html)
+ { :page => {:html => @html, :haml => @haml}}.to_json
end
-def to_xml
- builder do |xml|
- xml.instruct!
- xml.page do
- xml.html do
- xml.cdata! @html
- end
- xml.haml do
- xml.cdata! @haml
- end
- end
- end
+
+post "/*" do
+ @html = params["page"]["html"]
+ @haml = convert(@html)
+ haml :index
+end
+
+def convert(html)
+ Haml::HTML.new(html, :erb => true, :xhtml => true).render
end
Oops, something went wrong.

0 comments on commit b508019

Please sign in to comment.