Sinatra and Haml: strange behaviour after gem update - sinatra

I've made a site using Haml and Sinatra. After the update (I guess it was after that) the site didn't work any more; here is a minimal example:
/app.rb:
require 'rubygems' if RUBY_VERSION < '1.9'
require 'sinatra'
require 'haml'
get "/" do
haml :index
end
/views/layout.haml
!!!
%html{ :xmlns => "http://ww.w3.org/1999/xhtml", :lang => "en", "xml:lang" => "en" }
%head
%title test
%body
= yield
/view/index.haml
%p test
and it throws me the following exception:
/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.2/lib/tilt/template.rb in initialize
raise ArgumentError, "file or block required" if (#file || block).nil?
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in new
template.new(path, 1, options)
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in block in compile_template
template.new(path, 1, options)
/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.2/lib/tilt.rb in fetch
#cache[key] ||= yield
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in compile_template
template_cache.fetch engine, data, options do
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in render
template = compile_template(engine, data, options, views)
/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in haml
render :haml, template, options, locals
I haven't really found a way to fix it, does anyone know how to interpret it?

I get the same error with Sinatra 1.3.0.a (the version you're using, which I assume is a release candidate and not a full release), but updating to the current latest (1.3.0.e) fixes it, as does downgrading to the latest stable release (1.2.6). So your answer is upgrade or downgrade.
You can load a specific version of a gem using:
gem "sinatra", "=1.2.6"
before you call require "sinatra", or you could look into using Bundler (which uses the same syntax).

Related

Reprocessing - VSCode Reason Refmt breaks project

I'm hunting a fun little bug in a tiny reprocessing test: reprocessing01.
The project builds just fine until I make a change and trigger refmt via vscode, and then the project will no longer compile.
Here's the code that compiles and runs just fine for me before making any changes.
open Reprocessing;
type stateT = {
image: imageT,
};
let setup = (env) => {
Env.size(~width=800, ~height=600, env);
let image = Draw.loadImage(
~filename="assets/Wave_pattern_by_inkelv1122_on_flickr_800w.jpg",
~isPixel=false, env);
{
image: image
}
};
let draw = ({image} as state, env) => {
Draw.background(Constants.white, env);
Draw.image(
image,
~pos=(0,0),
~width=Env.width(env),
~height=Env.height(env),
env
);
state
};
run(~setup, ~draw, ());
If I open the project in vscode, make a change such as adding let myvar = 42; at the top, and save to trigger refmt, that introduces this error:
/Users/myer/dev/react/reasonml-playground/reprocessing01/node_modules/bs-platform/lib/bsc.exe -pp "/Users/myer/dev/react/reasonml-playground/reprocessing01/node_modules/bs-platform/lib/refmt3.exe --print binary" -bs-super-errors -w -30-40+6+7+27+32..39+44+45+101 -bs-D BSB_BACKEND="bytecode" -nostdlib -I '/Users/myer/dev/react/reasonml-playground/reprocessing01/node_modules/bs-platform/lib/ocaml' -no-alias-deps -color always -c -o src/index.mlast -bs-syntax-only -bs-simple-binary-ast -bs-binary-ast -impl /Users/myer/dev/react/reasonml-playground/reprocessing01/src/index.re
File "/Users/myer/dev/react/reasonml-playground/reprocessing01/src/index.re", line 12, characters 4-5:
Error: 2817: <UNKNOWN SYNTAX ERROR>
The line in question is the last one of this code block:
Draw.loadImage(
~filename="assets/Wave_pattern_by_inkelv1122_on_flickr_800w.jpg",
~isPixel=false,
env,
);
After this, the only way out is to revert the code to before the changes introduced by refmt.
I suspect that my version of refmt is out of sync with the one required by bsb-native#2.1.1, but I'm not sure which one to install. I have:
$ refmt --version
Reason 3.0.0 # bee43b0
Is there a table that shows compatible versions between reason-cli and bs-platform?
Are there other ways I should investigate this issue or other potential root causes of this behavior?
UPDATE:
I was able to upgrade bsb-native to the master branch and it worked when building to native until I added some more code in reprocessing02
this issue is because bsb-native#2.1.1 comes with an old version of refmt (pre version 3) which can't read the code that your global refmt outputs (most likely because of the trailing commas). I'm working on making a new release 3.2.0 on all platforms, which comes with the latest refmt. If you're on OSX you can try it by just changing your dep to bsansouci/bsb-native#3.2.0, nuking node_modules and reinstalling.
Sorry for the inconvenience. I'm planning on making my release cycle tighly coupled with bsb's release cycle.

Perl Invalid version format from Compat.pm

I'm trying to publish a module, and am running into a lot of weird errors, the latest of which is as follows:
C:\Shared\John\Perl\unifdef+.0.5.1>build disttest
Creating Makefile.PL
Invalid version format (non-numeric data) at C:/perl/lib/Module/Build/Compat.pm
line 134.
The code at the specified line is:
if ( my $minimum_perl = $requires->{perl} ) {
my $min_ver = version->new($minimum_perl)->numify;
print {$fh} "require $min_ver;\n";
}
so it looks like $minimum_perl is corrupted. I do have the line:
require 5.10.0;
In the code, but that should be OK according to the documentation I've read.
I tried upgrading various modules, and finally I tried a cpan upgrade, and upgraded my entire cpan, but I'm still getting the error. Can anyone tell me what I'm doing wrong? I am running perl 5.24.1
Ok, figured it out (sort of). I'm posting an answer, as I assume others will run into the same problem, and hopefully this will help them. My Build.PL script was a cut/paste/modify from an example on the web. I had the following:
use 5.010000; # NOT 5.8.8 - needed by CPAN testers
use Module::Build;
my $builder = Module::Build->new( module_name => 'code::unifdef+'
, license => 'perl'
, requires => { perl => '>= 5.10.0' } #hmm, this doesn't work...
, dist_version => '0.005.001'
, dist_author => 'John Ulvr <perldev#ulvr.com>'
, dist_abstract => 'processes conditional parts of makefiles, c/c++ and kconfig files'
, create_readme => 0
, create_makefile_pl => 'traditional'
);
$builder->create_build_script; #generate Build
The requires line was causing the problem. I'm not sure why though, as I've seen other similar examples on the web of the requires clause, so either everyone is wrong, or there's some sort of bug in in Compat.pm. Removing the requires line fixes the problem (I have requires in the .pl file itself, so it should catch out-of-date issues).

cucumber test gives error - Selenium::WebDriver::Error::JavascriptError

i have a tinymca's iframe inside my page and i want to fill_in that tinymca editor with the cucumber test. whenever i run my test it gives me error that jQuery not defined
in my Gemfile
source 'http://rubygems.org'
ruby '2.0.0'
gem 'capybara'
gem 'capybara-mechanize', :git => 'git://github.com/JerryWho/capybara-mechanize.git', :branch => 'relative-redirects'
gem 'rspec'
gem 'cucumber'
gem 'launchy'
gem 'pry'
gem 'selenium-webdriver'
here is my scenario
Scenario: admin puts all the valid and require data
when Job added with all the valid and require data
Then I should see the success message.
and here is the steps for that test
Given(/^I am logged in as a company admin$/) do
visit('/')
fill_in "log", :with => "admin#email.com"
fill_in "pwd", :with => "password"
click_button "submit"
end
When(/^Job added with all the valid and require data$/) do
visit('/site/admin/posts/add/')
within_frame 'questiontextarea_ifr' do
page.execute_script("jQuery(tinymce.editors[0].setContent('my content hersssssssssse'))")
end
click_button "Save"
end
Then(/^I should see the success message\.$/) do
page.should have_content('Success Your post has been successfully added.')
end
but it gives me error jQuery is not defined (Selenium::WebDriver::Error::JavascriptError)
It's most likely because "jQuery is not defined", as the message suggested.
Please try call without jQuery, but with native TinyMCE API:
page.execute_script("tinyMCE.activeEditor.setContent('my content hersssssssssse')")
Further reading: Test WYSIWYG editors using Selenium WebDriver in pure Ruby (not Capybara)

Sinatra: Template engine not found: prawn

I'm a newbie with Sinatra and prawn. I succeeded with erb and xmm/builder templates. Now trying to get pdf generation with prawn working.
Error received: Template engine not found: prawn
Code:
require 'rubygems'
require 'sinatra'
require 'sinatra/prawn'
set :prawn, { :page_layout => :portrait }
get '/pdf' do
content_type 'application/pdf'
prawn :pdf1
end
Thanks.
Found it: The gem from sbfaulkner doesn't work with current version of Sinatra.
Fix: install the forked gem from danielberkompas as follows:
gem install dberkom-sinatra-prawn -s http://gems.github.com
See issue 6
Then the above code works fine.

Scss/Sass not working with sinatra-assetpack

I'm writing a classic style sinatra app, and trying to package my scss files with sinatra-assetpack, but it's not working.
This is my main web file:
require 'rubygems'
require 'sinatra'
require 'haml'
require 'sass'
require 'compass'
require 'sinatra/assetpack'
set :root, File.dirname(__FILE__)
set :environment, ENV["RACK_ENV"] || "development"
configure do
Compass.configuration do |config|
config.project_path = File.dirname(__FILE__)
config.sass_dir = 'views/stylesheets'
end
set :haml, { :format => :html5 }
set :scss, Compass.sass_engine_options
assets {
serve '/javascripts', from: 'public/javascripts'
serve '/stylesheets', from: '/stylesheets'
# The second parameter defines where the compressed version will be served.
# (Note: that parameter is optional, AssetPack will figure it out.)
js :lib, '/javascripts/script.js', [
'/javascripts/lib/modernizr-2.5.3.js',
'/javascripts/lib/underscore-min.js',
'/javascripts/lib/slides.min.jquery.js',
'/javascripts/lib/jquery.scrollTo-1.4.2-min.js'
]
css :app, '/stylesheets/screen.css', [
'/stylesheets/screen.css',
'/fonts/meta.css'
]
js_compression :jsmin
css_compression :sass
}
end
I'm using this in my layout file:
= css :app, :media => 'screen'
The screen.scss file is stored in /views/stylesheets/screen.scss, and the meta.css is in /public/fonts/meta.css. Are the references to screen.css incorrect? Should they be served from a different directory?
Also I had this in my main web file
get '/stylesheets/screen.css' do
content_type 'text/css', :charset => 'utf-8'
scss :'stylesheets/screen'
end
Putting it in or removing it didn't fix anything - is this route necessary?
You should not keep your get '/stylesheets/screen.css' route anymore.
I also noticed you have compass in your Gemfile / app files. Sinatra AssetPack notes that it is not compatible with compass. You can include sinatra/support though to use it such as their example application here.
Change your serve '/stylesheets', from: '/stylesheets' statement to serve '/stylesheets', from: '/views/stylesheets' to reflect where you would like to serve the sass files from.
After all that, you should be able to serve your javascript and scss like below:
= css :app, :media => 'screen'
= js :lib