Skip to content
This repository

add stylus template support #553

Closed
wants to merge 3 commits into from

4 participants

Juan David Pastas Don't Add Me To Your Organization a.k.a The Travis Bot Konstantin Haase Lucas Mazza
Juan David Pastas

I'm having tests failing, but it seems to be due to:

  1. missed libraries,
  2. and some other thing I don't imagine (\a character),

see:

  1) Error:
test_can_be_used_in_a_nested_fashion_for_partials_and_whatnot(BlueClothTest):
Encoding::InvalidByteSequenceError: "\xF9" on UTF-8

  2) Failure:
test_renders_inline_markdown_strings(BlueClothTest) [/Users/adiaz/projects/Rubymine/sinatra-stylus/sinatra/test/markdown_test.rb:26]:
<"<h1>Hiya</h1>"> expected but was
<"<h1>Hiya</h1>\a">.

  3) Failure:
test_renders_with_file_layouts(BlueClothTest) [/Users/adiaz/projects/Rubymine/sinatra-stylus/sinatra/test/markdown_test.rb:55]:
<"ERB Layout!<p>Hello World</p>"> expected but was
<"ERB Layout!<p>Hello World</p>ap/">.

  4) Failure:
test_renders_with_inline_layouts(BlueClothTest) [/Users/adiaz/projects/Rubymine/sinatra-stylus/sinatra/test/markdown_test.rb:47]:
<"THIS.IS.<P>SPARTA</P>!"> expected but was
<"THIS.IS.<P>SPARTA</P>\a!">.

  5) Failure:
test_renders_inline_Stylus_strings(StylusTest) [/Users/adiaz/projects/Rubymine/sinatra-stylus/sinatra/test/stylus_test.rb:23]:
waiting response on how stylus can be rendered inline

960 tests, 1774 assertions, 4 failures, 1 errors, 0 skips

I put a pending message in fifth failure

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged b18310f into 91bce0b).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged b18310f into 91bce0b).

Konstantin Haase
Owner
rkh commented

Any news on "waiting response on how stylus can be rendered inline"? I'd like to include this in 1.4.0.

Konstantin Haase
Owner

Could you remove that assert false, '...' part and add Stylus to the Gemfile, so we see this running on Travis?

test/stylus_test.rb
((8 lines not shown))
  8 + rescue Exception
  9 + raise LoadError, 'unable to find Stylus compiler'
  10 + end
  11 +
  12 + class StylusTest < Test::Unit::TestCase
  13 + def stylus_app(options = {}, &block)
  14 + mock_app do
  15 + set :views, File.dirname(__FILE__) + '/views'
  16 + set(options)
  17 + get('/', &block)
  18 + end
  19 + get '/'
  20 + end
  21 +
  22 + it 'renders inline Stylus strings' do
  23 + stylus_app { stylus "a margin auto\n" }
7

I think that this string should be "a\n margin auto\n", with the proper linebreak after the selector, just like a similar test in scss_test.rb

I run tests again. I have not noticed that I am skipping tests, terminal says

unable to find Stylus compiler: skipping stylus tests

I don't understand how to correctly configure load path for testing. I have stylus gem installed, and I have tried

ruby -I~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/stylus-0.6.2 test/stylus_test.rb
ruby test/stylus_test.rb

Can you help me with this? I'm also having same problem with v8, bluecloth, and red carpet.

After cloning your fork I just did bundle install && rake test. Some unrelated tests were skipped, but Stylus one were executed since stylus is on the Gemfile. You could try that and see if it works for you.

My bundle is complete... hmmm, don't know what could be happening

hmmm, lol I don't have nodejs installed, that fixed the problem :p

See my comment on line 8 that's directly related to your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/stylus_test.rb
... ... @@ -0,0 +1,89 @@
  1 +require File.expand_path('../helper', __FILE__)
  2 +
  3 +begin
  4 + require 'stylus'
  5 +
  6 + begin
  7 + Stylus.compile '1'
  8 + rescue Exception
4

stylus throws a RuntimeError when the runtime isn't available, so I think would be better to rescue for just RuntimeError instead of Exception here, so it won't swallow any other kind of setup issue that might appear.

Modified to RuntimeError, but raising LoadError, is this OK?

I'm not sure if this intermediate rescue is necessary, since being part of the bundle won't issue any LoadError anytime soon.

Maybe message should say something related to the error I was having... nodejs not installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Juan David Pastas juanpastas add \n in inline template in stylus test
change caught error when loading stylus
5a101bb
Konstantin Haase
Owner

This needs a rebase.

Konstantin Haase
Owner

This seems to depend on Tilt edge. :(

Konstantin Haase
Owner

Let me correct this: It does not seem Tilt has any support for stylus. How did you run the tests?

Konstantin Haase
Owner

Ah, found it. I need to load both stylus and stylus/tilt.

Konstantin Haase rkh closed this in 1d48a75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Jul 30, 2012
Juan David Pastas juanpastas add stylus template support b18310f
Dec 13, 2012
Juan David Pastas juanpastas remove pending in stylus test, add stylus as dependency c1e0504
Dec 17, 2012
Juan David Pastas juanpastas add \n in inline template in stylus test
change caught error when loading stylus
5a101bb
This page is out of date. Refresh to see the latest.
1  Gemfile
@@ -44,6 +44,7 @@ gem 'markaby'
44 44 gem 'radius'
45 45 gem 'wlang', '>= 2.0.1'
46 46 gem 'rabl' unless RUBY_ENGINE == 'jruby'
  47 +gem 'stylus'
47 48
48 49 if RUBY_ENGINE == 'jruby'
49 50 gem 'nokogiri', '!= 1.5.0'
6 README.es.rdoc
Source Rendered
@@ -536,6 +536,12 @@ Dependencias:: {coffee-script}[https://github.com/josh/ruby-coffee-s
536 536 Extensiones de Archivo:: <tt>.coffee</tt>
537 537 Ejemplo:: <tt>coffee :index</tt>
538 538
  539 +=== Plantillas Stylus
  540 +
  541 +Dependencias:: {ruby-stylus}[https://github.com/lucasmazza/ruby-stylus]
  542 +Extensiones de Archivo:: <tt>.styl</tt>
  543 +Ejemplo:: <tt>stylus :index</tt>
  544 +
539 545 === Plantillas Yajl
540 546
541 547 Dependencias:: {yajl-ruby}[https://github.com/brianmario/yajl-ruby]
6 README.rdoc
Source Rendered
@@ -520,6 +520,12 @@ Dependency:: {coffee-script}[https://github.com/josh/ruby-coffee-script]
520 520 File Extensions:: <tt>.coffee</tt>
521 521 Example:: <tt>coffee :index</tt>
522 522
  523 +=== Stylus Templates
  524 +
  525 +Dependency:: {ruby-stylus}[https://github.com/lucasmazza/ruby-stylus]
  526 +File Extensions:: <tt>.styl</tt>
  527 +Example:: <tt>stylus :index</tt>
  528 +
523 529 === Yajl Templates
524 530
525 531 Dependency:: {yajl-ruby}[https://github.com/brianmario/yajl-ruby]
5 lib/sinatra/base.rb
@@ -598,6 +598,11 @@ def less(template, options={}, locals={})
598 598 render :less, template, options, locals
599 599 end
600 600
  601 + def stylus(template, options={}, locals={})
  602 + options.merge! :layout => false, :default_content_type => :css
  603 + render :styl, template, options, locals
  604 + end
  605 +
601 606 def builder(template=nil, options={}, locals={}, &block)
602 607 options[:default_content_type] = :xml
603 608 render_ruby(:builder, template, options, locals, &block)
89 test/stylus_test.rb
... ... @@ -0,0 +1,89 @@
  1 +require File.expand_path('../helper', __FILE__)
  2 +
  3 +begin
  4 + require 'stylus'
  5 +
  6 + begin
  7 + Stylus.compile '1'
  8 + rescue RuntimeError
  9 + raise LoadError, 'unable to find Stylus compiler'
  10 + end
  11 +
  12 + class StylusTest < Test::Unit::TestCase
  13 + def stylus_app(options = {}, &block)
  14 + mock_app do
  15 + set :views, File.dirname(__FILE__) + '/views'
  16 + set(options)
  17 + get('/', &block)
  18 + end
  19 + get '/'
  20 + end
  21 +
  22 + it 'renders inline Stylus strings' do
  23 + stylus_app { stylus "a\n margin auto\n" }
  24 + assert ok?
  25 + assert body.include?("a {\n margin: auto;\n}\n")
  26 + end
  27 +
  28 + it 'defaults content type to css' do
  29 + stylus_app { stylus :hello }
  30 + assert ok?
  31 + assert_equal "text/css;charset=utf-8", response['Content-Type']
  32 + end
  33 +
  34 + it 'defaults allows setting content type per route' do
  35 + stylus_app do
  36 + content_type :html
  37 + stylus :hello
  38 + end
  39 + assert ok?
  40 + assert_equal "text/html;charset=utf-8", response['Content-Type']
  41 + end
  42 +
  43 + it 'defaults allows setting content type globally' do
  44 + stylus_app(:styl => { :content_type => 'html' }) do
  45 + stylus :hello
  46 + end
  47 + assert ok?
  48 + assert_equal "text/html;charset=utf-8", response['Content-Type']
  49 + end
  50 +
  51 + it 'renders .styl files in views path' do
  52 + stylus_app { stylus :hello }
  53 + assert ok?
  54 + assert_include body, "a {\n margin: auto;\n}\n"
  55 + end
  56 +
  57 + it 'ignores the layout option' do
  58 + stylus_app { stylus :hello, :layout => :layout2 }
  59 + assert ok?
  60 + assert_include body, "a {\n margin: auto;\n}\n"
  61 + end
  62 +
  63 + it "raises error if template not found" do
  64 + mock_app {
  65 + get('/') { stylus :no_such_template }
  66 + }
  67 + assert_raise(Errno::ENOENT) { get('/') }
  68 + end
  69 +
  70 + it "passes stylus options to the stylus engine" do
  71 + stylus_app { stylus :hello, :no_wrap => true }
  72 + assert ok?
  73 + assert_body "a {\n margin: auto;\n}\n"
  74 + end
  75 +
  76 + it "passes default stylus options to the stylus engine" do
  77 + mock_app do
  78 + set :stylus, :no_wrap => true # default stylus style is :nested
  79 + get('/') { stylus :hello }
  80 + end
  81 + get '/'
  82 + assert ok?
  83 + assert_body "a {\n margin: auto;\n}\n"
  84 + end
  85 + end
  86 +
  87 +rescue LoadError
  88 + warn "#{$!.to_s}: skipping stylus tests"
  89 +end
2  test/views/hello.styl
... ... @@ -0,0 +1,2 @@
  1 +a
  2 + margin auto

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.