webs 0.1.26 → 0.1.27
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/cache/cache.rb +26 -13
- data/lib/controller/webs_controller.rb +9 -1
- data/lib/helper/application.rb +29 -0
- data/lib/views/layouts/webs_page.html.erb +1 -0
- data/lib/webs.rb +1 -1
- data/webs.gemspec +2 -2
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/cache/cache.rb
CHANGED
@@ -2,26 +2,39 @@ module Webs
|
|
2
2
|
mattr_accessor :cache
|
3
3
|
module Cache
|
4
4
|
mattr_accessor :debug
|
5
|
+
mattr_accessor :off
|
5
6
|
|
6
7
|
def cache_remove(key)
|
7
|
-
Rails.logger.debug "*********** cache_remove(#{key})" if debug
|
8
|
+
Rails.logger.debug "*********** cache_remove(#{key})" if debug && !off
|
8
9
|
return if key.nil?
|
9
10
|
Webs.cache.delete(key.to_s)
|
10
11
|
rescue Exception => e
|
11
12
|
Rails.logger.error "------------------------------------------------\nmemcache_error: #{e.message}"
|
12
13
|
false
|
13
14
|
end
|
14
|
-
|
15
|
-
def
|
16
|
-
Rails.logger.debug "***********
|
17
|
-
return if key.nil?
|
18
|
-
|
15
|
+
|
16
|
+
def cache_read( key )
|
17
|
+
Rails.logger.debug "*********** cache_read(#{key})" if debug #&& !off
|
19
18
|
if Webs.cache.respond_to?( 'read' )
|
20
|
-
|
19
|
+
Webs.cache.read(key)
|
21
20
|
else
|
22
|
-
|
21
|
+
Webs.cache[ key ]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def cache_block(key, options=nil, &block)
|
26
|
+
return if key.nil?
|
27
|
+
if off
|
28
|
+
if self.respond_to?('capture')
|
29
|
+
data = capture(&block) # called from view
|
30
|
+
else
|
31
|
+
data = yield
|
32
|
+
end
|
33
|
+
Rails.logger.debug "****OFF**** cache_block(#{key})"
|
34
|
+
return data
|
23
35
|
end
|
24
|
-
|
36
|
+
|
37
|
+
unless ( data=cache_read(key) )
|
25
38
|
if self.respond_to?('capture')
|
26
39
|
data = capture(&block) # called from view
|
27
40
|
else
|
@@ -32,17 +45,17 @@ module Webs
|
|
32
45
|
#TODO: Check to see if dalli cache & compressed then up the size to 3MB
|
33
46
|
# should get almost 10:1 compression ratio. This will be key for caching pages & fragments
|
34
47
|
if block_size < 1.megabyte
|
35
|
-
Rails.logger.debug "*********** cache_block[#{block_size}](#{key}, #{data} )" if debug
|
48
|
+
Rails.logger.debug "*********** cache_block[#{block_size}](#{key}, #{data && data.inspect.length > 100 ? data.inspect[0..100] : data} )" if debug && !off
|
36
49
|
if Webs.cache.respond_to?( 'write' )
|
37
50
|
Webs.cache.write(key, data)
|
38
51
|
else
|
39
52
|
Webs.cache[ key ] = data
|
40
53
|
end
|
41
54
|
else
|
42
|
-
Rails.logger.debug "***********
|
55
|
+
Rails.logger.debug "*********** cache_block(#{key}) not cached since exceeds 3M @ #{block_size} )" if debug && !off
|
43
56
|
end
|
44
57
|
else
|
45
|
-
Rails.logger.debug "****HIT**** cache_block(#{key}
|
58
|
+
Rails.logger.debug "****HIT**** cache_block(#{key} )" if debug && !off
|
46
59
|
end
|
47
60
|
data
|
48
61
|
rescue Exception => e
|
@@ -50,4 +63,4 @@ module Webs
|
|
50
63
|
data
|
51
64
|
end
|
52
65
|
end
|
53
|
-
end
|
66
|
+
end
|
@@ -79,7 +79,15 @@ module Webs
|
|
79
79
|
|
80
80
|
url = url_for( options.merge(:only_path=>true) ) if url.blank?
|
81
81
|
|
82
|
-
render_text = %
|
82
|
+
render_text = %[<fw:redirect url="#{url}">Redirecting, please wait...]
|
83
|
+
if partials && partials.any?
|
84
|
+
partials.each do |p|
|
85
|
+
p = render_to_string( :partial=>p )
|
86
|
+
Rails.logger.debug "************ PARTIAL=> #{p}"
|
87
|
+
render_text += p
|
88
|
+
end
|
89
|
+
end
|
90
|
+
render_text += %[</fw:redirect>]
|
83
91
|
Rails.logger.debug render_text
|
84
92
|
render :text => render_text
|
85
93
|
end
|
data/lib/helper/application.rb
CHANGED
@@ -44,6 +44,35 @@ module Webs
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
# break text every col
|
48
|
+
def text_breaking_wrap(txt, col = 80)
|
49
|
+
return nil if txt.blank?
|
50
|
+
txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3 ")
|
51
|
+
end
|
52
|
+
|
53
|
+
# break text every col respecting tags
|
54
|
+
def html_breaking_wrap(html, col=80)
|
55
|
+
# Breakup the string by html tags
|
56
|
+
tag_regex = /<\/?[^>]*>/
|
57
|
+
if html && html =~ tag_regex
|
58
|
+
# Breakup the string by html tags
|
59
|
+
ss = StringScanner.new( html )
|
60
|
+
a = []
|
61
|
+
while ( ss.scan_until(tag_regex) )
|
62
|
+
a << ss.pre_match if !ss.pre_match.blank?
|
63
|
+
a << ss.matched
|
64
|
+
ss = StringScanner.new( ss.rest )
|
65
|
+
end
|
66
|
+
a << ss.rest if ss.rest?
|
67
|
+
|
68
|
+
# For each non-tag break long words
|
69
|
+
a.collect{ |s| s[0..0]=='<' ? s : text_breaking_wrap(s, col) }.join
|
70
|
+
else
|
71
|
+
text_breaking_wrap(html, col)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Great for all browsers but opera, but doesn't work in fw:sanitize
|
47
76
|
def breaking_wrap( s, max_width=5 )
|
48
77
|
return s if s.blank? || s.length < max_width
|
49
78
|
r = Regexp.new( ".{1,#{max_width}}" )
|
data/lib/webs.rb
CHANGED
data/webs.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{webs}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.27"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chuck Olczak"]
|
9
|
-
s.date = %q{2011-04-
|
9
|
+
s.date = %q{2011-04-19}
|
10
10
|
s.description = %q{Reusable webs stuff.}
|
11
11
|
s.email = %q{chuck@webs.com}
|
12
12
|
gemfiles = [
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: webs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.27
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chuck Olczak
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-19 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|