sinatra-cache 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.3.7
@@ -3,7 +3,7 @@ require 'sinatra/outputbuffer'
3
3
 
4
4
  module Sinatra
5
5
  module Cache
6
- VERSION = '0.3.6' unless const_defined?(:VERSION)
6
+ VERSION = '0.3.7' unless const_defined?(:VERSION)
7
7
  def self.version; "Sinatra::Cache v#{VERSION}"; end
8
8
  end #/ Cache
9
9
  end #/ Sinatra
@@ -416,7 +416,7 @@ module Sinatra
416
416
  content_2_cache << block_content
417
417
  content_2_cache << "<!-- /cache fragment: #{fragment_name} cached at [ #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] -->\n"
418
418
  else
419
- content_2_cache << block_content
419
+ content_2_cache = block_content
420
420
  end
421
421
  # 6. write it to cache
422
422
  cache_write_file(cf, content_2_cache)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra-cache}
8
- s.version = "0.3.6"
8
+ s.version = "0.3.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kematzy"]
12
- s.date = %q{2010-11-15}
12
+ s.date = %q{2011-04-08}
13
13
  s.description = %q{A Sinatra Extension that makes Page and Fragment Caching easy.}
14
14
  s.email = %q{kematzy@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -23,6 +23,7 @@ describe "Sinatra" do
23
23
  set :cache_environment, :test
24
24
  set :cache_output_dir, "#{test_cache_path('system/cache')}"
25
25
  set :cache_fragments_output_dir, "#{test_cache_path('system/cache')}_fragments"
26
+ set :cache_fragments_wrap_with_html_comments, false
26
27
 
27
28
  # NB! Although without tests, the positioning of the custom method in relation to other
28
29
  # Cache related declaration has no effect.
@@ -140,6 +141,10 @@ describe "Sinatra" do
140
141
  MyDefaultsTestApp.cache_logging_level.should == :info
141
142
  end
142
143
 
144
+ it "should set :cache_fragments_wrap_with_html_comments to true" do
145
+ MyDefaultsTestApp.cache_fragments_wrap_with_html_comments.should == true
146
+ end
147
+
143
148
  end #/ with Default Settings
144
149
 
145
150
  describe "with Custom Settings" do
@@ -172,6 +177,10 @@ describe "Sinatra" do
172
177
  MyTestApp.cache_logging_level.should == :info
173
178
  end
174
179
 
180
+ it "should set :cache_fragments_wrap_with_html_comments to false" do
181
+ MyTestApp.cache_fragments_wrap_with_html_comments.should == false
182
+ end
183
+
175
184
  end #/ Custom
176
185
 
177
186
  end #/ Configuration
@@ -520,84 +529,208 @@ describe "Sinatra" do
520
529
 
521
530
  describe "and Fragment caching" do
522
531
 
523
- describe "using NOT shared fragments" do
532
+ describe "with default settings" do
524
533
 
525
- after(:all) do
526
- FileUtils.rm_r("#{test_cache_path('system/cache')}_fragments/fragments") if @delete_cached_test_files
527
- end
534
+ def app; ::MyTestApp.new ; end
528
535
 
529
- %w(
530
- /fragments /fragments/a/b/ /fragments/with/param/?page=1
531
- /fragments/dasherised-urls/works-as-well
532
- ).each do |url|
536
+ describe "using NOT shared fragments" do
533
537
 
534
- params_free_url = url =~ /\?/ ? url.split('?').first.chomp('?') : url
535
- dir_structure = params_free_url.gsub(/^\//,'').gsub(/\/$/,'')
538
+ after(:all) do
539
+ FileUtils.rm_r("#{test_cache_path('system/cache')}_fragments/fragments") if @delete_cached_test_files
540
+ end
536
541
 
537
- it "should cache the fragments from the URL [#{url}] as [#{dir_structure}/test_fragment.html]" do
538
- get(url)
539
- # body.should have_tag(:debug)
540
- body.should have_tag('h1','FRAGMENTS', :count => 1)
541
- body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
542
- body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
542
+ %w(
543
+ /fragments /fragments/a/b/ /fragments/with/param/?page=1
544
+ /fragments/dasherised-urls/works-as-well
545
+ ).each do |url|
543
546
 
544
- # render the page a 2nd time from cache
545
- get(url)
546
- body.should have_tag('h1','FRAGMENTS', :count => 1)
547
- body.should match(/<!-- cache fragment:(.+)test_fragment -->/)
548
- body.should match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
547
+ params_free_url = url =~ /\?/ ? url.split('?').first.chomp('?') : url
548
+ dir_structure = params_free_url.gsub(/^\//,'').gsub(/\/$/,'')
549
549
 
550
- # the cached fragment has already been found if we get this far,
551
- # but just for good measure do we check for the existence of the fragment file.
552
- test(?f, "#{test_cache_path('system/cache')}_fragments/#{dir_structure}/test_fragment.html").should == true
550
+ it "should cache the fragments from the URL [#{url}] as [#{dir_structure}/test_fragment.html]" do
551
+ get(url)
552
+ # body.should have_tag(:debug)
553
+ body.should have_tag('h1','FRAGMENTS', :count => 1)
554
+ body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
555
+ body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
556
+
557
+ # render the page a 2nd time from cache
558
+ get(url)
559
+ body.should have_tag('h1','FRAGMENTS', :count => 1)
560
+ body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
561
+ body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
562
+
563
+ # the cached fragment has already been found if we get this far,
564
+ # but just for good measure do we check for the existence of the fragment file.
565
+ test(?f, "#{test_cache_path('system/cache')}_fragments/#{dir_structure}/test_fragment.html").should == true
566
+ end
553
567
  end
554
- end
568
+
569
+ end #/ using NOT shared fragments
570
+
571
+ describe "using shared fragments" do
572
+
573
+ after(:all) do
574
+ FileUtils.rm_r("#{test_cache_path('system/cache')}_fragments/sharedfragments") if @delete_cached_test_files
575
+ end
576
+
577
+ describe "when requesting the first URL" do
578
+
579
+ # FIXME:: work out some clever way to split all of these tests into single items instead of in one big blob
580
+
581
+ it "should cache the fragment based on the URL and use it on subsequent requests by URLs sharing the same root URL" do
582
+ url = '/sharedfragments/2010/02/some-article-01'
583
+ params_free_url = url =~ /\?/ ? url.split('?').first.chomp('?') : url
584
+ dir_structure = params_free_url.gsub(/^\//,'').gsub(/\/$/,'')
585
+ dirs = dir_structure.split('/')
586
+ dir_structure = dirs.first(dirs.length-1).join('/')
587
+
588
+ get(url)
589
+ # body.should have_tag(:debug)
590
+ body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
591
+ body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
592
+ body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
593
+
594
+ get(url)
595
+ body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
596
+ body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
597
+ body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
598
+
599
+ # the cached fragment has already been found if we get this far,
600
+ # but just for good measure do we check for the existence of the fragment file.
601
+ test(?f, "#{test_cache_path('system/cache')}_fragments/#{dir_structure}/test_fragment.html").should == true
602
+
603
+ # should use the cached fragment rather than cache a new fragment
604
+ url = '/sharedfragments/2010/02/another-article-02'
605
+ get(url)
606
+ body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
607
+ body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
608
+ body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
609
+ end
610
+
611
+ end #/ when requesting the first URL
612
+
613
+ end #/ using shared fragments
555
614
 
556
- end #/ using NOT shared fragments
615
+ end #/ with default settings
557
616
 
558
- describe "using shared fragments" do
617
+ describe "with :cache_fragments_wrap_with_html_comments enabled" do
559
618
 
560
- after(:all) do
561
- FileUtils.rm_r("#{test_cache_path('system/cache')}_fragments/sharedfragments") if @delete_cached_test_files
619
+ class MyWrapTestApp < Sinatra::Base
620
+
621
+ set :app_dir, "#{APP_ROOT}/apps/base"
622
+ set :public, "#{fixtures_path}/public"
623
+ set :views, "#{app_dir}/views"
624
+
625
+ register(Sinatra::Tests)
626
+
627
+ enable :raise_errors
628
+
629
+ register(Sinatra::Cache)
630
+
631
+ # need to set the root of the app for the default :cache_fragments_output_dir to work
632
+ set :root, ::APP_ROOT
633
+
634
+ set :cache_enabled, true
635
+ set :cache_environment, :test
636
+ set :cache_output_dir, "#{test_cache_path('system/cache')}"
637
+ set :cache_fragments_output_dir, "#{test_cache_path('system/cache')}_wrap_fragments"
638
+ set :cache_fragments_wrap_with_html_comments, true
639
+
640
+ get('/') { erb(:index) }
641
+
642
+ get %r{^/fragments/?([\s\w-]+)?/?([\w-]+)?/?([\w-]+)?/?([\w-]+)?/?([\w-]+)?/?([\w-]+)?} do
643
+ erb(:fragments, :layout => false, :cache => false)
644
+ end
645
+ get %r{^/sharedfragments/?([\s\w-]+)?/?([\w-]+)?/?([\w-]+)?/?([\w-]+)?/?([\w-]+)?/?([\w-]+)?} do
646
+ erb(:fragments_shared, :layout => false, :cache => false)
647
+ end
648
+
562
649
  end
563
650
 
564
- describe "when requesting the first URL" do
651
+ def app; ::MyWrapTestApp.new ; end
652
+
653
+ describe "using NOT shared fragments" do
654
+
655
+ after(:all) do
656
+ FileUtils.rm_r("#{test_cache_path('system/cache')}_wrap_fragments/fragments") if @delete_cached_test_files
657
+ end
565
658
 
566
- # FIXME:: work out some clever way to split all of these tests into single items instead of in one big blob
567
-
568
- it "should cache the fragment based on the URL and use it on subsequent requests by URLs sharing the same root URL" do
569
- url = '/sharedfragments/2010/02/some-article-01'
659
+ %w(
660
+ /fragments /fragments/a/b/ /fragments/with/param/?page=1
661
+ /fragments/dasherised-urls/works-as-well
662
+ ).each do |url|
663
+
570
664
  params_free_url = url =~ /\?/ ? url.split('?').first.chomp('?') : url
571
665
  dir_structure = params_free_url.gsub(/^\//,'').gsub(/\/$/,'')
572
- dirs = dir_structure.split('/')
573
- dir_structure = dirs.first(dirs.length-1).join('/')
574
666
 
575
- get(url)
576
- # body.should have_tag(:debug)
577
- body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
578
- body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
579
- body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
667
+ it "should cache the fragments from the URL [#{url}] as [#{dir_structure}/test_fragment.html]" do
668
+ get(url)
669
+ # body.should have_tag(:debug)
670
+ body.should have_tag('h1','FRAGMENTS', :count => 1)
671
+ body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
672
+ body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
673
+
674
+ # render the page a 2nd time from cache
675
+ get(url)
676
+ body.should have_tag('h1','FRAGMENTS', :count => 1)
677
+ body.should match(/<!-- cache fragment:(.+)test_fragment -->/)
678
+ body.should match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
679
+
680
+ # the cached fragment has already been found if we get this far,
681
+ # but just for good measure do we check for the existence of the fragment file.
682
+ test(?f, "#{test_cache_path('system/cache')}_wrap_fragments/#{dir_structure}/test_fragment.html").should == true
683
+ end
684
+ end
685
+
686
+ end #/ using NOT shared fragments
687
+
688
+ describe "using shared fragments" do
689
+
690
+ after(:all) do
691
+ FileUtils.rm_r("#{test_cache_path('system/cache')}_wrap_fragments/sharedfragments") if @delete_cached_test_files
692
+ end
693
+
694
+ describe "when requesting the first URL" do
580
695
 
581
- get(url)
582
- body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
583
- body.should match(/<!-- cache fragment:(.+)test_fragment -->/)
584
- body.should match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
696
+ # FIXME:: work out some clever way to split all of these tests into single items instead of in one big blob
585
697
 
586
- # the cached fragment has already been found if we get this far,
587
- # but just for good measure do we check for the existence of the fragment file.
588
- test(?f, "#{test_cache_path('system/cache')}_fragments/#{dir_structure}/test_fragment.html").should == true
698
+ it "should cache the fragment based on the URL and use it on subsequent requests by URLs sharing the same root URL" do
699
+ url = '/sharedfragments/2010/02/some-article-01'
700
+ params_free_url = url =~ /\?/ ? url.split('?').first.chomp('?') : url
701
+ dir_structure = params_free_url.gsub(/^\//,'').gsub(/\/$/,'')
702
+ dirs = dir_structure.split('/')
703
+ dir_structure = dirs.first(dirs.length-1).join('/')
704
+
705
+ get(url)
706
+ # body.should have_tag(:debug)
707
+ body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
708
+ body.should_not match(/<!-- cache fragment:(.+)test_fragment -->/)
709
+ body.should_not match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
710
+
711
+ get(url)
712
+ body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
713
+ body.should match(/<!-- cache fragment:(.+)test_fragment -->/)
714
+ body.should match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
715
+
716
+ # the cached fragment has already been found if we get this far,
717
+ # but just for good measure do we check for the existence of the fragment file.
718
+ test(?f, "#{test_cache_path('system/cache')}_wrap_fragments/#{dir_structure}/test_fragment.html").should == true
719
+
720
+ # should use the cached fragment rather than cache a new fragment
721
+ url = '/sharedfragments/2010/02/another-article-02'
722
+ get(url)
723
+ body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
724
+ body.should match(/<!-- cache fragment:(.+)test_fragment -->/)
725
+ body.should match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
726
+ end
589
727
 
590
- # should use the cached fragment rather than cache a new fragment
591
- url = '/sharedfragments/2010/02/another-article-02'
592
- get(url)
593
- body.should have_tag('h1','FRAGMENTS - SHARED', :count => 1)
594
- body.should match(/<!-- cache fragment:(.+)test_fragment -->/)
595
- body.should match(/<!-- \/cache fragment: test_fragment cached at \[ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\] -->/)
596
- end
728
+ end #/ when requesting the first URL
597
729
 
598
- end #/ when requesting the first URL
730
+ end #/ using shared fragments
599
731
 
600
- end #/ using shared fragments
732
+ end #/ with customs settings
733
+
601
734
 
602
735
  end #/ and Fragment caching
603
736
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-cache
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 6
10
- version: 0.3.6
9
+ - 7
10
+ version: 0.3.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - kematzy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-15 00:00:00 +08:00
18
+ date: 2011-04-08 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency