Skip to content

Commit

Permalink
Creating initial partials module, and adding Guard.
Browse files Browse the repository at this point in the history
  • Loading branch information
forrest committed Feb 27, 2012
1 parent 07b56d1 commit f4ed43e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ gem "spork", ">= 0.9.0"
gem "rspec-rails"
gem "mocha"
gem "appraisal"

gem "guard"
gem "guard-spork"
gem "guard-rspec"
15 changes: 15 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
end

guard 'rspec', :cli => "--drb", :all_after_pass => false, :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/prawnto/(.+)\.rb$}) { |m| "spec/units/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end

2 changes: 1 addition & 1 deletion lib/prawnto/template_handlers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.call(template)

"_prawnto_compile_setup;" +
"renderer = Prawnto::TemplateHandlers::Renderer.new(self);"+
"renderer.to_pdf do; #{template.source}\nend;"
"renderer.to_pdf(self) do; #{template.source}\nend;"
end

private
Expand Down
13 changes: 13 additions & 0 deletions lib/prawnto/template_handlers/partials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Prawnto
module TemplateHandlers
module Partials

def render_partial(path, prawn_object = pdf)
# get the path
# get file contents (should include a cache somehow?)
# prawn_object.instance_eval partial_contents
end

end
end
end
7 changes: 6 additions & 1 deletion lib/prawnto/template_handlers/renderer.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
require "prawnto/template_handlers/partials"

module Prawnto
module TemplateHandlers
class Renderer
include Partials

def initialize(view_context, calling_object = nil)
@view_context = view_context
@calling_object = calling_object
set_instance_variables
@pdf = Prawn::Document.new(@prawnto_options[:prawn]);
end

def to_pdf(&block)
def to_pdf(scope = false, &block)
@_scope = scope
instance_eval(&block)
@pdf.render.html_safe
end
Expand Down
7 changes: 1 addition & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@

Rails.backtrace_cleaner.remove_silencers!

# Load support files
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

RSpec.configure do |config|
config.mock_with :mocha

config.infer_base_class_for_anonymous_controllers = false
end

TEST_ASSETS = File.expand_path("assets", File.dirname(__FILE__)).to_s

TEST_ASSETS = File.expand_path("assets", File.dirname(__FILE__)).to_s
end

Spork.each_run do
# This code will be run each time you run your specs.

end

# Helper to provide asset path given the "base name" of the file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
require "spec_helper"

describe TestController do

class PrawntoControllerWithInlineTrue < TestController
prawnto :inline=>true, :prawn=>{:page_orientation=>:landscape}
end

it "Controller should start with the defaults" do
@controller = TestController.new
@controller.send(:compute_prawnto_options).should == {:inline=>true, :prawn => {}}
Expand All @@ -15,22 +15,22 @@ class PrawntoControllerWithInlineTrue < TestController
it "should store prawn_hash" do
PrawntoControllerWithInlineTrue.prawn_hash.should == {:page_orientation=>:landscape}
end

it "should store prawnto_hash" do
PrawntoControllerWithInlineTrue.prawnto_hash.should == {:inline=>true}
end
end

describe "#prawnto" do
before do
@controller = TestController.new
@controller.send(:prawnto, {:inline=>false})
end

it "should affect that controller" do
@controller.send(:compute_prawnto_options).should == {:inline=>false, :prawn => {}}
end

it "should not affect the controller class" do
PrawntoControllerWithInlineTrue.new.send(:compute_prawnto_options).should == {:inline=>true, :prawn=>{:page_orientation=>:landscape}}
end
Expand Down
12 changes: 6 additions & 6 deletions spec/units/compile_support_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
require "spec_helper"

describe Prawnto::CompileSupport do

before do
@request = mock()
@request.stubs(:ssl?).returns(false)
Expand All @@ -18,7 +18,7 @@
Prawnto::CompileSupport.any_instance.stubs(:set_cache_control).returns(true)
Prawnto::CompileSupport.any_instance.stubs(:set_content_type).returns(Mime::PDF)
end

it "default" do
@headers.expects("[]=").with("Content-Disposition", "inline").once
Prawnto::CompileSupport.new(@controller)
Expand All @@ -29,19 +29,19 @@
@headers.expects("[]=").with("Content-Disposition", "inline;filename=\"xxx.pdf\"").once
Prawnto::CompileSupport.new(@controller)
end

it "attachment with filename" do
@controller.stubs(:compute_prawnto_options).returns({:filename => "xxx.pdf", :inline => false})
@headers.expects("[]=").with("Content-Disposition", "attachment;filename=\"xxx.pdf\"").once
Prawnto::CompileSupport.new(@controller)
end

end

describe "#set_pragma" do
pending
end

describe "#set_cache_control" do
pending
end
Expand Down
4 changes: 4 additions & 0 deletions spec/units/template_handlers/renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require "spec_helper"

describe Prawnto::TemplateHandlers::Renderer do
end

0 comments on commit f4ed43e

Please sign in to comment.