webs 0.1.37 → 0.1.38
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 +4 -4
- data/lib/controller/webs_controller.rb +0 -1
- data/lib/helper/tags.rb +83 -71
- data/lib/views/layouts/webs_page.html.erb +1 -0
- data/lib/views/layouts/webs_utility.html.erb +1 -0
- data/lib/webs.rb +8 -6
- data/webs.gemspec +2 -2
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/cache/cache.rb
CHANGED
@@ -42,18 +42,18 @@ module Webs
|
|
42
42
|
nil
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def cache_capture_data( &block )
|
46
46
|
self.respond_to?('capture') ? capture(&block) : yield
|
47
47
|
end
|
48
48
|
|
49
49
|
def cache_block(key, options={}, &block)
|
50
50
|
return if key.nil?
|
51
51
|
Rails.logger.debug "*********** cache_block( #{key} )" if debug
|
52
|
-
return
|
52
|
+
return cache_capture_data( &block ) if off
|
53
53
|
|
54
54
|
unless ( data=cache_read(key) )
|
55
55
|
# if self responds to capture this is called from a view which means we can cache snippets
|
56
|
-
data =
|
56
|
+
data = cache_capture_data( &block )
|
57
57
|
cache_write( key.to_s, data, options )
|
58
58
|
end
|
59
59
|
data
|
@@ -71,7 +71,7 @@ module Webs
|
|
71
71
|
def cache_snippet(snippet, key, options={}, &block)
|
72
72
|
return snippet.html_safe if !snippet.blank?
|
73
73
|
if options.delete(:ignore_cache)
|
74
|
-
|
74
|
+
cache_capture_data( &block )
|
75
75
|
else
|
76
76
|
cache_block( key, options, &block )
|
77
77
|
end
|
data/lib/helper/tags.rb
CHANGED
@@ -8,49 +8,110 @@ module Webs
|
|
8
8
|
# Renders:
|
9
9
|
#
|
10
10
|
# <fw:blah>HELLO<fw:fwml_attribute name="value"><fw:name uid="xxx"/></fw:fwml_attribute></fw:blah>
|
11
|
+
# can take an option: :tokens which is a hash for replacement and will add in the appropriate fw:intl-token tags
|
12
|
+
# ex:
|
13
|
+
# <%= fwml :intl, :description=>"bogus", :tokens=>{ :tier=>"Tier 1", :image_limit=>"10", :upgrade_link=>"www.blah.com" } do %>
|
14
|
+
# As a {tier} member, each of your products can have a maximum of {image_limit}.
|
15
|
+
# Need more? Time to upgrade!
|
16
|
+
# {upgrade_link}
|
17
|
+
# <% end %>
|
18
|
+
#
|
19
|
+
# Should Yield:
|
20
|
+
#
|
21
|
+
# <fw:intl description="bogus">
|
22
|
+
# As a {tier} member, each of your products can have a maximum of {image_limit}.
|
23
|
+
# Need more? Time to upgrade!
|
24
|
+
# {upgrade_link}
|
25
|
+
# <fw:intl-token name="tier">Tier 1</fw:intl-token>
|
26
|
+
# <fw:intl-token name="image_limit">10</fw:intl-token>
|
27
|
+
# <fw:intl-token name="upgrade_link">www.blah.com</fw:intl-token>
|
28
|
+
# </fw:intl>
|
29
|
+
#
|
30
|
+
# You should also be able to use it without a body, so this should work:
|
31
|
+
# <% rubystring = 'hello world' %>
|
32
|
+
# <%= fwml :intl, :value=rubystring %>
|
33
|
+
#
|
34
|
+
# Should Yield
|
35
|
+
#
|
36
|
+
# <fw:intl>hello world</fw:intl>
|
37
|
+
#
|
11
38
|
|
12
39
|
def fwml tagname, options={}, &block
|
13
|
-
attributes = options.delete( :fw_attributes )
|
14
40
|
# Rails.logger.debug "****** fwml #{tagname} #{options.inspect}"
|
15
41
|
tagname = tagname.to_s unless tagname.nil?
|
16
|
-
if ['sanitize', 'wizzywig'
|
42
|
+
if ['sanitize', 'wizzywig'].include?(tagname)
|
17
43
|
tag = self.send( "fw_#{tagname}", options, &block )
|
18
44
|
else
|
19
45
|
if block
|
20
46
|
tag = render_tag_with_block tagname, options, false, &block
|
21
47
|
else
|
22
|
-
tag = inline_tag( tagname,
|
48
|
+
tag = inline_tag( tagname, options )
|
23
49
|
end
|
24
50
|
end
|
25
51
|
|
26
|
-
|
27
|
-
tagidx = tag.length - (tagname.length + 6)
|
28
|
-
attribute_str = attributes.keys.collect{ |k| %[<fw:fwml-attribute name="#{k}">#{attributes[k]}</fw:fwml-attribute>] }.join( "\n" )
|
29
|
-
tag = tag[0..tagidx-1] + attribute_str.html_safe + tag[tagidx..tag.length-1]
|
30
|
-
end
|
31
|
-
|
32
|
-
tag.html_safe
|
52
|
+
html_safe_check( tag )
|
33
53
|
end
|
34
54
|
|
35
55
|
private
|
56
|
+
def html_safe_check s
|
57
|
+
return s if s.blank?
|
58
|
+
s.respond_to?( 'html_safe' ) ? s.html_safe : s
|
59
|
+
end
|
60
|
+
|
36
61
|
def html_options options
|
37
62
|
' ' + options.each_key.select{ |k| !options[k].blank? }.collect{|k| "#{k.to_s}=\"#{options[k]}\"" }.join(' ') if options.any?
|
38
63
|
end
|
64
|
+
|
65
|
+
def parse_fwml_options tagname, options
|
66
|
+
s = ''
|
67
|
+
if ( attrs = options.delete( :fw_attributes ) )
|
68
|
+
s += attr_hash.keys.collect{ |k| %[<fw:fwml-attribute name="#{k}">#{attributes[k]}</fw:fwml-attribute>] }.join( "\n" )
|
69
|
+
end
|
70
|
+
if ( intl_attrs = options.delete( :fw_intl_attrs ) )
|
71
|
+
s += attr_hash.keys.collect{ |k| %[<fw:fwml-attribute name="#{k}">#{attributes[k]}</fw:fwml-attribute>] }.join( "\n" )
|
72
|
+
end
|
73
|
+
if tagname == 'intl' && ( tokens = options.delete( :tokens ) )
|
74
|
+
s += token_str = tokens.keys.collect{ |k| %[<fw:intl-token name="#{k}">#{tokens[k]}</fw:intl-token>] }.join( "\n" )
|
75
|
+
end
|
76
|
+
s
|
77
|
+
end
|
39
78
|
|
40
79
|
def render_tag_with_block tagname, options, cdata_wrapper=false, &block
|
41
|
-
# Rails.logger.debug "****** render_tag_with_block #{tagname} #{options.inspect} cdata=#{cdata_wrapper}"
|
42
80
|
content = capture(&block)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
output
|
48
|
-
|
81
|
+
|
82
|
+
# parse attributes to append before closing tag
|
83
|
+
append_str = parse_fwml_options tagname, options
|
84
|
+
|
85
|
+
output = begin
|
86
|
+
ActiveSupport::SafeBuffer.new
|
87
|
+
rescue
|
88
|
+
nil
|
89
|
+
end
|
90
|
+
|
91
|
+
if output
|
92
|
+
# RAILS3
|
93
|
+
output.safe_concat("<fw:#{tagname}#{html_options(options)}>")
|
94
|
+
output.safe_concat("<![CDATA[") if cdata_wrapper
|
95
|
+
output << content
|
96
|
+
output.safe_concat( append_str ) if !append_str.blank?
|
97
|
+
output.safe_concat("]]>") if cdata_wrapper
|
98
|
+
output.safe_concat("</fw:#{tagname}>")
|
99
|
+
else
|
100
|
+
# RAILS2
|
101
|
+
concat("<fw:#{tagname}#{html_options(options)}>", block.binding)
|
102
|
+
concat("<![CDATA[", block.binding) if cdata_wrapper
|
103
|
+
concat( content, block.binding)
|
104
|
+
concat( append_str, block.binding ) if !append_str.blank?
|
105
|
+
concat("]]>", block.binding) if cdata_wrapper
|
106
|
+
concat("</fw:#{tagname}>", block.binding)
|
107
|
+
end
|
49
108
|
end
|
50
109
|
|
51
|
-
def inline_tag( tagname,
|
52
|
-
if
|
53
|
-
|
110
|
+
def inline_tag( tagname, options={} )
|
111
|
+
value = options.delete( :value ) if ['intl'].include?(tagname)
|
112
|
+
append_str = parse_fwml_options tagname, options
|
113
|
+
if !append_str.blank? || !value.blank?
|
114
|
+
"<fw:#{tagname}#{html_options(options)}>#{value}#{append_str}</fw:#{tagname}>"
|
54
115
|
else
|
55
116
|
"<fw:#{tagname}#{html_options(options)}/>"
|
56
117
|
end
|
@@ -65,57 +126,8 @@ module Webs
|
|
65
126
|
# fw_wizzywig should never be called with a block the text is passed in via text
|
66
127
|
def fw_wizzywig options={}
|
67
128
|
wizzywig_text = options.delete( :wizzywig_text )
|
68
|
-
"<fw:wizzywig #{html_options(options)}><![CDATA[#{wizzywig_text}]]></fw:wizzywig>"
|
129
|
+
html_safe_check "<fw:wizzywig #{html_options(options)}><![CDATA[#{wizzywig_text}]]></fw:wizzywig>"
|
69
130
|
end
|
70
|
-
|
71
|
-
# can take an option: :tokens which is a hash for replacement and will add in the appropriate fw:intl-token tags
|
72
|
-
# ex:
|
73
|
-
# <%= fwml :intl, :description=>"bogus", :tokens=>{ :tier=>"Tier 1", :image_limit=>"10", :upgrade_link=>"www.blah.com" } do %>
|
74
|
-
# As a {tier} member, each of your products can have a maximum of {image_limit}.
|
75
|
-
# Need more? Time to upgrade!
|
76
|
-
# {upgrade_link}
|
77
|
-
# <% end %>
|
78
|
-
#
|
79
|
-
# Should Yield:
|
80
|
-
#
|
81
|
-
# <fw:intl description="bogus">
|
82
|
-
# As a {tier} member, each of your products can have a maximum of {image_limit}.
|
83
|
-
# Need more? Time to upgrade!
|
84
|
-
# {upgrade_link}
|
85
|
-
# <fw:intl-token name="tier">Tier 1</fw:intl-token>
|
86
|
-
# <fw:intl-token name="image_limit">10</fw:intl-token>
|
87
|
-
# <fw:intl-token name="upgrade_link">www.blah.com</fw:intl-token>
|
88
|
-
# </fw:intl>
|
89
|
-
#
|
90
|
-
# You should also be able to use it without a body, so this should work:
|
91
|
-
# <% rubystring = 'hello world' %>
|
92
|
-
# <%= fwml :intl, :value=rubystring %>
|
93
|
-
#
|
94
|
-
# Should Yield
|
95
|
-
#
|
96
|
-
# <fw:intl>hello world</fw:intl>
|
97
|
-
#
|
98
|
-
def fw_intl options={}, &block
|
99
|
-
|
100
|
-
value = options.delete( :value)
|
101
|
-
tokens = options.delete( :tokens )
|
102
|
-
if block
|
103
|
-
tag = render_tag_with_block 'intl', options, false, &block
|
104
|
-
|
105
|
-
idx = tag.length - 10
|
106
|
-
token_str = tokens.keys.collect{ |k| %[<fw:intl-token name="#{k}">#{tokens[k]}</fw:intl-token>] }.join( "\n" )
|
107
|
-
(tag[0..idx-1] + token_str.html_safe + tag[idx..tag.length-1]).html_safe
|
108
|
-
else
|
109
|
-
%[<fw:intl#{html_options(options)}>#{h value}</fw:intl>].html_safe
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
131
|
+
end
|
113
132
|
end
|
114
133
|
end
|
115
|
-
|
116
|
-
# No support for rails 2
|
117
|
-
# concat("<fw:#{tagname}#{s_options}>", block.binding)
|
118
|
-
# concat("<![CDATA[") if cdata_wrapper
|
119
|
-
# concat( content, block.binding)
|
120
|
-
# concat("]]>") if cdata_wrapper
|
121
|
-
# concat("</fw:#{tagname}>", block.binding)
|
data/lib/webs.rb
CHANGED
@@ -7,16 +7,18 @@ require dir + 'helper/params'
|
|
7
7
|
require dir + 'helper/tags'
|
8
8
|
|
9
9
|
module Webs
|
10
|
-
VERSION = '0.1.
|
10
|
+
VERSION = '0.1.38'.freeze
|
11
11
|
|
12
12
|
def self.app_title
|
13
13
|
APP_NAME.titleize
|
14
14
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
path
|
19
|
-
|
15
|
+
|
16
|
+
if defined?( Rails::Railtie )
|
17
|
+
class Railtie < Rails::Railtie
|
18
|
+
initializer 'webs_view-path' do |app|
|
19
|
+
path = "#{Pathname(__FILE__).dirname.expand_path}/views"
|
20
|
+
app.paths.app.views.push path
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
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.38"
|
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-06-
|
9
|
+
s.date = %q{2011-06-02}
|
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.38
|
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-06-
|
13
|
+
date: 2011-06-02 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|