viewfu 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ "Software"), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,62 @@
1
+ ViewFu
2
+ ======
3
+
4
+ ViewFu is a Rails3 plugin that provides all the miscellaneous View tasks. It's a combination of the functionality of BrowserDetect, Headliner, Meta Tags - along with additional tweaks such as providing commonly used View Helpers Methods.
5
+
6
+ Maintainer Info
7
+ ======
8
+
9
+ Jacques Crocker
10
+ railsjedi.com
11
+
12
+ ViewFu HTML Helpers
13
+ =======
14
+ ViewFu provides helpers for commonly used html elements
15
+
16
+ br #=> <br />
17
+ hr #=> <hr />
18
+ anchor("posts") #=> <a name='posts'></a>
19
+ clear #=> <div class="clear"></div>
20
+ clear(:left) #=> <div class="clearleft"></div>
21
+ clear_tag(:br) #=> <br class="clear" />
22
+ lorem #=> Lorem ipsum dolor...
23
+
24
+ Haml Specific Helpers
25
+ =======
26
+ Haml allows you to pash a hash of attributes. ViewFu assists this by providing a simple "hidden" helper that allows you to conditionally hide page elements.
27
+
28
+ %div{hidden} #=> <div style="display:none">
29
+ %div{hidden(:if => @posts.empty?)} #=> hide the .posts div if the array is empty
30
+ %div{hidden(:unless => @posts.empty?)} #=> hide the empty posts message if the array has elements
31
+ %div{add_class("empty", :if => @posts.empty?)} #=> add the "empty" class if the array is empty
32
+
33
+ Meta Tags
34
+ =======
35
+ ViewFu allows you to set meta tags on your page header from anywhere. Just add a call to meta_tags somewhere in your page header.
36
+
37
+ meta_tags
38
+ output all the html meta tags currently on the page
39
+
40
+ meta_keywords
41
+ output the meta keywords tag
42
+
43
+ meta_keywords(val)
44
+ set the page meta keywords
45
+
46
+ meta_description
47
+ output the meta description tag
48
+
49
+ meta_description(val)
50
+ set the page meta description
51
+
52
+ Browser Detect
53
+ =======
54
+
55
+ browser_is? :ie
56
+ browser_is? :ie6
57
+ browser_is? :ie7
58
+ browser_is? :iphone
59
+ browser_is? :webkit
60
+ browser_is? :firefox
61
+
62
+ Released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "viewfu"
7
+ s.summary = "rails3 view helpers"
8
+ s.email = "railsjedi@gmail.com"
9
+ s.homepage = "http://github.com/railsjedi/viewfu"
10
+ s.description = "Lots of little tidbits for tidying up your views"
11
+ s.authors = ["Jacques Crocker"]
12
+ s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+
16
+ rescue LoadError
17
+ # puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
data/lib/view_fu.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "view_fu/tag_helper"
2
+ require "view_fu/meta_helper"
3
+ require "view_fu/browser_detect"
4
+
5
+ if defined?(Rails) and defined?(ActionView)
6
+ ActionView::Base.send :include, ViewFu::MetaHelper
7
+ ActionView::Base.send :include, ViewFu::TagHelper
8
+ ActionView::Base.send :include, ViewFu::BrowserDetect
9
+ end
10
+
@@ -0,0 +1,46 @@
1
+ module ViewFu
2
+ module BrowserDetect
3
+ # check the current browser (via user agent) for the following:
4
+ # :mozilla / :firefox
5
+ # :ie6
6
+ # :ie7
7
+ # :ie
8
+ # :iphone
9
+ # :safari
10
+ def browser_is? name
11
+ name = name.to_s.strip
12
+
13
+ return true if browser_name == name
14
+ return true if (name == 'mozilla' or name == "firefox") && browser_name == 'gecko'
15
+ return true if name == 'ie6' && browser_name.index('ie6')
16
+ return true if name == 'ie7' && browser_name.index('ie7')
17
+ return true if name == 'ie' && browser_name.index('ie')
18
+ return true if name == 'iphone' && browser_name == 'iphone'
19
+ return true if name == 'webkit' && browser_name == 'safari'
20
+ end
21
+
22
+ # find the current browser name
23
+ def browser_name
24
+ @browser_name ||= begin
25
+ ua = request.user_agent.to_s.downcase
26
+ if ua.index('msie') && !ua.index('opera') && !ua.index('webtv')
27
+ 'ie'+ua[ua.index('msie')+5].chr
28
+ elsif ua.index('gecko/')
29
+ 'gecko'
30
+ elsif ua.index('opera')
31
+ 'opera'
32
+ elsif ua.index('konqueror')
33
+ 'konqueror'
34
+ elsif ua.index('iphone')
35
+ 'iphone'
36
+ elsif ua.index('applewebkit/')
37
+ 'safari'
38
+ elsif ua.index('mozilla/')
39
+ 'gecko'
40
+ else
41
+ ""
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,51 @@
1
+ module ViewFu
2
+ module MetaHelper
3
+ # Output the current page's meta tags
4
+ def meta_tags
5
+ %(
6
+ <meta name="keywords" content="#{meta_keywords}" />
7
+ <meta name="description" content="#{meta_description}" />
8
+ ).html_safe
9
+ end
10
+
11
+ # Get/Set Meta Keywords
12
+ def meta_keywords(meta_keywords = nil)
13
+ if meta_keywords
14
+ @__meta_keywords = meta_keywords
15
+ else
16
+ @__meta_keywords ||= ""
17
+
18
+ # Check if we have AppConfig to use for default
19
+ if defined? AppConfig
20
+ default_meta_keywords = AppConfig.default_meta_keywords
21
+ else
22
+ default_meta_keywords = ""
23
+ end
24
+
25
+ # set the default if meta_keywords is blank
26
+ @__meta_keywords = default_meta_keywords if @__meta_keywords.blank?
27
+ end
28
+ return @__meta_keywords.to_s.html_safe
29
+ end
30
+
31
+ # Get/Set Meta Description
32
+ def meta_description(meta_description = nil)
33
+ if meta_description
34
+ @__meta_description = meta_description
35
+ else
36
+ @__meta_description ||= ""
37
+
38
+ # Check if we have AppConfig to use for default
39
+ if defined? AppConfig
40
+ default_meta_description = AppConfig.default_meta_description
41
+ else
42
+ default_meta_description = ""
43
+ end
44
+
45
+ # set the default if meta_description is blank
46
+ @__meta_description = default_meta_description if @__meta_description.blank?
47
+ end
48
+ return @__meta_description.to_s.html_safe
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,145 @@
1
+ module ViewFu
2
+ module TagHelper
3
+ # Writes a br tag
4
+ def br
5
+ "<br />".html_safe
6
+ end
7
+
8
+ # Writes an hr tag
9
+ def hr
10
+ "<hr />".html_safe
11
+ end
12
+
13
+ # Writes a nonbreaking space
14
+ def nbsp
15
+ "&nbsp;".html_safe
16
+ end
17
+
18
+ # Writes an anchor tag
19
+ def anchor(anchor_name, options = {})
20
+ content_tag(:a, "", options.merge(:name => anchor_name))
21
+ end
22
+
23
+ # Writes a clear tag
24
+ def clear_tag(tag, direction = nil)
25
+ if tag == :br
26
+ "<br class=\"clear#{direction}\" />".html_safe
27
+ else
28
+ "<#{tag} class=\"clear#{direction}\"></#{tag}>".html_safe
29
+ end
30
+ end
31
+
32
+ def current_year
33
+ Time.now.strftime("%Y")
34
+ end
35
+
36
+ # Writes a clear div tag
37
+ def clear(direction = nil)
38
+ clear_tag(:div, direction)
39
+ end
40
+
41
+ # Return some lorem text
42
+ def lorem
43
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
44
+ end
45
+
46
+ # provides a slick way to add classes inside haml attribute collections
47
+ #
48
+ # examples:
49
+ # %div{add_class("current")}
50
+ # #=> adds the "current" class to the div
51
+ #
52
+ # %div{add_class("current", :if => current?)}
53
+ # #=> adds the "current" class to the div if current? method
54
+ #
55
+ # %div{add_class("highlight", :unless => logged_in?)}
56
+ # #=> adds the "highlight" class to the div unless logged_in? method returns true
57
+ def add_class(css_class, options = {})
58
+ return {} unless css_class
59
+
60
+ if options.has_key?(:unless) && options[:unless]
61
+ return {}
62
+ end
63
+
64
+ if options.has_key?(:if) && options[:if]
65
+ return {:class => css_class}
66
+ end
67
+
68
+ if !options.has_key?(:if) and !options.has_key?(:unless)
69
+ {:class => css_class}
70
+ else
71
+ {}
72
+ end
73
+ end
74
+
75
+ def add_class_if(css_class, condition)
76
+ add_class(css_class, :if => condition)
77
+ end
78
+
79
+ def add_class_unless(css_class, condition)
80
+ add_class(css_class, :unless => condition)
81
+ end
82
+
83
+ # Return a hidden attribute hash (useful in Haml tags - %div{hidden})
84
+ def hide(options = {})
85
+ if options.has_key?(:unless) && options[:unless]
86
+ return {}
87
+ end
88
+
89
+ if options.has_key?(:if) && !options[:if]
90
+ return {}
91
+ end
92
+
93
+ {:style => "display:none"}
94
+ end
95
+ alias :hidden :hide
96
+
97
+ # Return a hidden attribute hash if a condition evaluates to true
98
+ def hide_if(condition)
99
+ hide(:if => condition)
100
+ end
101
+ alias :hidden_if :hide_if
102
+ alias :show_unless :hide_if
103
+
104
+ # Return a hidden attribute hash if a condition evaluates to false
105
+ def hide_unless(condition)
106
+ hide(:unless => condition)
107
+ end
108
+ alias :hidden_unless :hide_unless
109
+ alias :show_if :hide_unless
110
+
111
+ # Wrap a delete link
112
+ def delete_link(*args)
113
+ options = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(extract_options_from_args!(args)||{})
114
+ args << options
115
+ link_to(*args)
116
+ end
117
+
118
+ # Wrap a block with a link
119
+ def link_to_block(*args, &block)
120
+ content = capture(&block)
121
+ return link_to(content, *args)
122
+ end
123
+
124
+ # Check if we're on production environment
125
+ def production?
126
+ Rails.env.production?
127
+ end
128
+
129
+ # clearbit icons
130
+ def clearbit_icon(icon, color, options = {})
131
+ image_tag "clearbits/#{icon}.gif", {:class => "clearbits #{color}", :alt => icon}.merge(options)
132
+ end
133
+
134
+ # pixel spacing helper
135
+ def pixel(options = {})
136
+ image_tag "pixel.png", options
137
+ end
138
+
139
+ # check to see if an index is the first item in a collection
140
+ def is_first(i)
141
+ i.to_i.zero? ? {:class => "first"} : {}
142
+ end
143
+
144
+ end
145
+ end
data/lib/viewfu.rb ADDED
@@ -0,0 +1 @@
1
+ require "view_fu"
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: viewfu
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jacques Crocker
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-15 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Lots of little tidbits for tidying up your views
22
+ email: railsjedi@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README
30
+ files:
31
+ - LICENSE
32
+ - README
33
+ - Rakefile
34
+ - VERSION
35
+ - lib/view_fu.rb
36
+ - lib/view_fu/browser_detect.rb
37
+ - lib/view_fu/meta_helper.rb
38
+ - lib/view_fu/tag_helper.rb
39
+ - lib/viewfu.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/railsjedi/viewfu
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.6
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: rails3 view helpers
70
+ test_files: []
71
+