merb_viewfu 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +81 -0
- data/Rakefile +51 -0
- data/lib/browser_detect/helper.rb +47 -0
- data/lib/headliner/README +118 -0
- data/lib/headliner/helper.rb +65 -0
- data/lib/merb_viewfu.rb +19 -0
- data/lib/view_fu/meta_helper.rb +51 -0
- data/lib/view_fu/tag_helper.rb +167 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/viewfu_spec.rb +7 -0
- metadata +76 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jacques Crocker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
ViewFu
|
2
|
+
======
|
3
|
+
|
4
|
+
ViewFu is a Merb 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
|
+
Tyler Crocker
|
10
|
+
NeoRails.com
|
11
|
+
|
12
|
+
Looking for *the one* awesome rails developer to add to your project? I may be available to help out. Contact me at neorails@gmail.com.
|
13
|
+
|
14
|
+
|
15
|
+
ViewFu HTML Helpers
|
16
|
+
=======
|
17
|
+
ViewFu provides helpers for commonly used html elements
|
18
|
+
|
19
|
+
br #=> <br />
|
20
|
+
hr #=> <hr />
|
21
|
+
anchor("posts") #=> <a name='posts'></a>
|
22
|
+
clear #=> <div class="clear"></div>
|
23
|
+
clear(:left) #=> <div class="clearleft"></div>
|
24
|
+
clear_tag(:br) #=> <br class="clear" />
|
25
|
+
lorem #=> Lorem ipsum dolor...
|
26
|
+
|
27
|
+
|
28
|
+
ViewFu Helper Queries
|
29
|
+
=======
|
30
|
+
production? #=> returns true if Rails.env == "production"
|
31
|
+
|
32
|
+
|
33
|
+
ViewFu Misc Helpers
|
34
|
+
=======
|
35
|
+
paging(@array) #=> display a will_paginate paging links (only if the array is a valid paging collection)
|
36
|
+
paging(@array, :sabros) #=> wrap the paging links with a class "sabros"
|
37
|
+
|
38
|
+
|
39
|
+
Haml Specific Helpers
|
40
|
+
=======
|
41
|
+
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.
|
42
|
+
|
43
|
+
%div{hidden} #=> <div style="display:none">
|
44
|
+
%div.posts{hidden_if(@posts.empty?)} #=> hide the .posts div if the array is empty
|
45
|
+
%p.empty{hidden_unless(@posts.empty?)} #=> hide the empty posts message if the array has elements
|
46
|
+
|
47
|
+
Page Titles
|
48
|
+
=======
|
49
|
+
ViewFu allows you to easily set the current page title from anywhere on your views
|
50
|
+
|
51
|
+
title
|
52
|
+
Displays the current page title
|
53
|
+
|
54
|
+
title(new_title)
|
55
|
+
Sets the page title
|
56
|
+
|
57
|
+
See lib/headliner/README for more details
|
58
|
+
|
59
|
+
|
60
|
+
Meta Tags
|
61
|
+
=======
|
62
|
+
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.
|
63
|
+
|
64
|
+
meta_tags
|
65
|
+
output all the html meta tags currently on the page
|
66
|
+
|
67
|
+
meta_keywords
|
68
|
+
output the meta keywords tag
|
69
|
+
|
70
|
+
meta_keywords(val)
|
71
|
+
set the page meta keywords
|
72
|
+
|
73
|
+
meta_description
|
74
|
+
output the meta description tag
|
75
|
+
|
76
|
+
meta_description(val)
|
77
|
+
set the page meta description
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
Copyright (c) 2008 NeoRails.com, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
require 'merb-core'
|
5
|
+
require 'merb-core/tasks/merb'
|
6
|
+
|
7
|
+
GEM_NAME = "merb_viewfu"
|
8
|
+
GEM_VERSION = "0.2"
|
9
|
+
AUTHOR = "Jacques Crocker"
|
10
|
+
EMAIL = "merbjedi@gmail.com"
|
11
|
+
HOMEPAGE = "http://merbjedi.com/"
|
12
|
+
SUMMARY = "View Helpers for Title, Meta tags, Browser Detect, and Common Tag Helpers"
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.rubyforge_project = 'merb'
|
16
|
+
s.name = GEM_NAME
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README", "LICENSE"]
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.author = AUTHOR
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
s.add_dependency('merb', '>= 1.0')
|
27
|
+
s.require_path = 'lib'
|
28
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,spec}/**/*")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
33
|
+
pkg.gem_spec = spec
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "install the plugin as a gem"
|
37
|
+
task :install do
|
38
|
+
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Uninstall the gem"
|
42
|
+
task :uninstall do
|
43
|
+
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Create a gemspec file"
|
47
|
+
task :gemspec do
|
48
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
49
|
+
file.puts spec.to_ruby
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module BrowserDetect
|
2
|
+
module Helper
|
3
|
+
|
4
|
+
# check the current browser (via user agent) for the following:
|
5
|
+
# :mozilla / :firefox
|
6
|
+
# :ie6
|
7
|
+
# :ie7
|
8
|
+
# :ie
|
9
|
+
# :iphone
|
10
|
+
# :safari
|
11
|
+
def browser_is? name
|
12
|
+
name = name.to_s.strip
|
13
|
+
|
14
|
+
return true if browser_name == name
|
15
|
+
return true if (name == 'mozilla' or name == "firefox") && browser_name == 'gecko'
|
16
|
+
return true if name == 'ie6' && browser_name.index('ie6')
|
17
|
+
return true if name == 'ie7' && browser_name.index('ie7')
|
18
|
+
return true if name == 'ie' && browser_name.index('ie')
|
19
|
+
return true if name == 'iphone' && browser_name == 'iphone'
|
20
|
+
return true if name == 'webkit' && browser_name == 'safari'
|
21
|
+
end
|
22
|
+
|
23
|
+
# find the current browser name
|
24
|
+
def browser_name
|
25
|
+
@browser_name ||= begin
|
26
|
+
ua = request.user_agent.to_s.downcase
|
27
|
+
if ua.index('msie') && !ua.index('opera') && !ua.index('webtv')
|
28
|
+
'ie'+ua[ua.index('msie')+5].chr
|
29
|
+
elsif ua.index('gecko/')
|
30
|
+
'gecko'
|
31
|
+
elsif ua.index('opera')
|
32
|
+
'opera'
|
33
|
+
elsif ua.index('konqueror')
|
34
|
+
'konqueror'
|
35
|
+
elsif ua.index('iphone')
|
36
|
+
'iphone'
|
37
|
+
elsif ua.index('applewebkit/')
|
38
|
+
'safari'
|
39
|
+
elsif ua.index('mozilla/')
|
40
|
+
'gecko'
|
41
|
+
else
|
42
|
+
""
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
=========
|
2
|
+
Headliner
|
3
|
+
=========
|
4
|
+
|
5
|
+
Headliner DRYs up your page titles.
|
6
|
+
|
7
|
+
|
8
|
+
Background
|
9
|
+
==========
|
10
|
+
|
11
|
+
Normally, if your Rails application has lots of actions and a shared
|
12
|
+
layout, you might find yourself setting custom page title names in your
|
13
|
+
controllers.
|
14
|
+
|
15
|
+
Here's an example:
|
16
|
+
|
17
|
+
class PagesController < ApplicationController
|
18
|
+
def about
|
19
|
+
@title = "About us"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Then, in your main layout, you might have something like this:
|
24
|
+
|
25
|
+
<head>
|
26
|
+
<title>My website<% if @title %>: <%= @title %><% end %></title>
|
27
|
+
</head
|
28
|
+
|
29
|
+
This works okay... but page titles don't really belong in controllers, do
|
30
|
+
they?
|
31
|
+
|
32
|
+
So, by moving these titles into your views, we can DRY things up a bit and
|
33
|
+
reinforce the MVC design pattern that's so fundamental to Ruby on Rails.
|
34
|
+
|
35
|
+
|
36
|
+
Usage
|
37
|
+
=====
|
38
|
+
|
39
|
+
First, add this code to your main layout:
|
40
|
+
|
41
|
+
<head>
|
42
|
+
<%= title :site => "My website" %>
|
43
|
+
</head>
|
44
|
+
|
45
|
+
Then, to set the page title, add this to each of your views:
|
46
|
+
|
47
|
+
<h1><%= title "My page title" %></h1>
|
48
|
+
|
49
|
+
When views are rendered, the page title will be included in the right
|
50
|
+
spots:
|
51
|
+
|
52
|
+
<head>
|
53
|
+
<title>My website | My page title</title>
|
54
|
+
</head>
|
55
|
+
<body>
|
56
|
+
<h1>My page title</h1>
|
57
|
+
</body>
|
58
|
+
|
59
|
+
|
60
|
+
Options
|
61
|
+
=======
|
62
|
+
|
63
|
+
Use these options to customize the title format:
|
64
|
+
|
65
|
+
:prefix (text between site name and separator)
|
66
|
+
:separator (text used to separate website name from page title)
|
67
|
+
:suffix (text between separator and page title)
|
68
|
+
:lowercase (when true, the page name will be lowercase)
|
69
|
+
:reverse (when true, the page and site names will be reversed)
|
70
|
+
|
71
|
+
And here are a few examples to give you ideas.
|
72
|
+
|
73
|
+
<%= title :separator => "—" %>
|
74
|
+
<%= title :prefix => false, :separator => ":" %>
|
75
|
+
<%= title :lowercase => true %>
|
76
|
+
<%= title :reverse => true, :prefix => false %>
|
77
|
+
|
78
|
+
|
79
|
+
Dealing with special pages
|
80
|
+
==========================
|
81
|
+
|
82
|
+
How do you set the page title without showing it in the view?
|
83
|
+
|
84
|
+
<% title "My page title" %>
|
85
|
+
|
86
|
+
What if your view headline is different from your page title?
|
87
|
+
|
88
|
+
<%= title "My page title", "My headline" %>
|
89
|
+
|
90
|
+
|
91
|
+
Mr. T says, ‘Use my method, fool!’
|
92
|
+
==================================
|
93
|
+
|
94
|
+
Just like ERB's HTML safe method, you can invoke Headliner with a single
|
95
|
+
letter alias.
|
96
|
+
|
97
|
+
<h1><%=t "My page title" %></h1>
|
98
|
+
|
99
|
+
|
100
|
+
How does it work?
|
101
|
+
=================
|
102
|
+
|
103
|
+
Ruby on Rails renders actions *before* inserting them into layouts. So, if
|
104
|
+
you set a variable in your view, it will be accessible in your layout. But,
|
105
|
+
at first glance, it looks like you're using a variable (in the head)
|
106
|
+
before it's been assigned a value (in the body). Cool, huh?
|
107
|
+
|
108
|
+
|
109
|
+
Credits
|
110
|
+
=======
|
111
|
+
|
112
|
+
Special thanks to Nick Zadrozny and Jordan Fowler for their input.
|
113
|
+
|
114
|
+
|
115
|
+
Feedback
|
116
|
+
========
|
117
|
+
|
118
|
+
Comments, bug reports, and svn diffs welcome at http://the.railsi.st.
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Headliner
|
2
|
+
module Helper
|
3
|
+
def title(options, headline='')
|
4
|
+
if options.is_a? String
|
5
|
+
save_title(options, headline)
|
6
|
+
else
|
7
|
+
display_title(options)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def save_title(title, headline)
|
12
|
+
@title = title.gsub(/<\/?[^>]*>/, '')
|
13
|
+
headline.blank? ? title : headline
|
14
|
+
end
|
15
|
+
|
16
|
+
def display_title(options)
|
17
|
+
# Prefix (leading space)
|
18
|
+
if options[:prefix]
|
19
|
+
prefix = options[:prefix]
|
20
|
+
elsif options[:prefix] == false
|
21
|
+
prefix = ''
|
22
|
+
else
|
23
|
+
prefix = ' '
|
24
|
+
end
|
25
|
+
|
26
|
+
# Separator
|
27
|
+
unless options[:separator].blank?
|
28
|
+
separator = options[:separator]
|
29
|
+
else
|
30
|
+
separator = '|'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Suffix (trailing space)
|
34
|
+
if options[:suffix]
|
35
|
+
suffix = options[:suffix]
|
36
|
+
elsif options[:suffix] == false
|
37
|
+
suffix = ''
|
38
|
+
else
|
39
|
+
suffix = ' '
|
40
|
+
end
|
41
|
+
|
42
|
+
# Lowercase title?
|
43
|
+
if options[:lowercase] == true
|
44
|
+
@title = @title.downcase unless @title.blank?
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set website/page order
|
48
|
+
unless @title.blank?
|
49
|
+
if options[:reverse] == true
|
50
|
+
# Reverse order => "Page : Website"
|
51
|
+
return tag(:title, @title + prefix + separator + suffix + options[:site])
|
52
|
+
else
|
53
|
+
# Standard order => "Website : Page"
|
54
|
+
return tag(:title, options[:site] + prefix + separator + suffix + @title)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# If title is blank, return only website name
|
59
|
+
tag :title, options[:site]
|
60
|
+
end
|
61
|
+
|
62
|
+
# Mr. T says, "Use my method, fool!"
|
63
|
+
alias t title
|
64
|
+
end
|
65
|
+
end
|
data/lib/merb_viewfu.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "view_fu/tag_helper"
|
2
|
+
require "view_fu/meta_helper"
|
3
|
+
|
4
|
+
require "browser_detect/helper"
|
5
|
+
require "headliner/helper"
|
6
|
+
|
7
|
+
# make sure we're running inside Merb
|
8
|
+
if defined?(Merb::Plugins)
|
9
|
+
|
10
|
+
# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
|
11
|
+
Merb::Plugins.config[:viewfu] = {}
|
12
|
+
|
13
|
+
Merb::BootLoader.before_app_loads do
|
14
|
+
Merb::Controller.send(:include, ViewFu::MetaHelper)
|
15
|
+
Merb::Controller.send(:include, ViewFu::TagHelper)
|
16
|
+
Merb::Controller.send(:include, Headliner::Helper)
|
17
|
+
Merb::Controller.send(:include, BrowserDetect::Helper)
|
18
|
+
end
|
19
|
+
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
|
+
)
|
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
|
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
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
module ViewFu
|
2
|
+
module TagHelper
|
3
|
+
|
4
|
+
# Writes a br tag
|
5
|
+
def br
|
6
|
+
"<br />"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Writes an hr tag
|
10
|
+
def hr
|
11
|
+
"<hr />"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Writes a nonbreaking space
|
15
|
+
def nbsp
|
16
|
+
" "
|
17
|
+
end
|
18
|
+
|
19
|
+
# ported from rails
|
20
|
+
def auto_discovery_link_tag(type = :rss, url = nil, tag_options = {})
|
21
|
+
|
22
|
+
# theres gotta be a better way of setting mimetype for a file extensionin Merb..
|
23
|
+
unless tag_options[:type]
|
24
|
+
if type.to_s == "rss"
|
25
|
+
tag_options[:type] = "application/rss+xml"
|
26
|
+
elsif type.to_s == "atom"
|
27
|
+
tag_options[:type] = "application/atom+xml"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
tag(:link, :rel => (tag_options[:rel] || "alternate"),
|
32
|
+
:type => tag_options[:type].to_s,
|
33
|
+
:title => (tag_options[:title] || type.to_s.upcase),
|
34
|
+
:href => (url || "#"))
|
35
|
+
end
|
36
|
+
|
37
|
+
# Writes an hr space tag
|
38
|
+
def space
|
39
|
+
"<hr class='space' />"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Writes an anchor tag
|
43
|
+
def anchor(anchor_name, options = {})
|
44
|
+
tag(:a, options.merge(:name => anchor_name)) do
|
45
|
+
""
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Writes a clear tag
|
50
|
+
def clear_tag(tag, direction = nil)
|
51
|
+
if tag == :br
|
52
|
+
"<br class=\"clear#{direction}\" />"
|
53
|
+
else
|
54
|
+
"<#{tag} class=\"clear#{direction}\"></#{tag}>"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def current_year
|
59
|
+
Time.now.strftime("%Y")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Writes a clear div tag
|
63
|
+
def clear(direction = nil)
|
64
|
+
clear_tag(:div, direction)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Return some lorem text
|
68
|
+
def lorem
|
69
|
+
"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."
|
70
|
+
end
|
71
|
+
|
72
|
+
# Return a hidden attribute hash (useful in Haml tags - %div{hidden})
|
73
|
+
def hidden
|
74
|
+
{:style => "display:none"}
|
75
|
+
end
|
76
|
+
|
77
|
+
# Easily link to an image
|
78
|
+
def link_to_image(image_path, label, url, options={})
|
79
|
+
# setup vertical alignment
|
80
|
+
vert_align = options.delete(:vert)
|
81
|
+
if vert_align.nil?
|
82
|
+
vert_style = "vertical-align: middle"
|
83
|
+
elsif vert_align.blank?
|
84
|
+
vert_style = ""
|
85
|
+
else
|
86
|
+
vert_style = "vertical-align: #{vert_align.to_i}px"
|
87
|
+
end
|
88
|
+
|
89
|
+
link_to(image_tag(image_path, :class => "vert-middle", :style => "#{vert_style}"), url, options)+" "+
|
90
|
+
link_to(label, url, options)
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_class_if(css_class, condition)
|
94
|
+
if condition
|
95
|
+
{:class => css_class}
|
96
|
+
else
|
97
|
+
{}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_class_unless(css_class, condition)
|
102
|
+
add_class_if(css_class, !condition)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Return a hidden attribute hash if a condition evaluates to true
|
106
|
+
def hide_if(condition)
|
107
|
+
if condition
|
108
|
+
hidden
|
109
|
+
else
|
110
|
+
{}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
alias :hidden_if :hide_if
|
114
|
+
alias :show_unless :hide_if
|
115
|
+
|
116
|
+
# Return a hidden attribute hash if a condition evaluates to false
|
117
|
+
def hide_unless(condition)
|
118
|
+
if !condition
|
119
|
+
hidden
|
120
|
+
else
|
121
|
+
{}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
alias :hidden_unless :hide_unless
|
125
|
+
alias :show_if :hide_unless
|
126
|
+
|
127
|
+
# Wrap a delete link
|
128
|
+
def delete_link(*args)
|
129
|
+
options = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(extract_options_from_args!(args)||{})
|
130
|
+
args << options
|
131
|
+
link_to(*args)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Wrap a block with a link
|
135
|
+
def link_to_block(*args, &block)
|
136
|
+
content = capture(&block)
|
137
|
+
return link_to(content, *args)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Check if we're on production environment
|
141
|
+
def production?
|
142
|
+
Merb.env == "production"
|
143
|
+
end
|
144
|
+
|
145
|
+
# Display will_paginate paging links
|
146
|
+
def paging(page_data, style = :sabros)
|
147
|
+
return unless page_data.is_a? WillPaginate::Collection
|
148
|
+
will_paginate(page_data, :class => "pagination #{style}", :inner_window => 3)
|
149
|
+
end
|
150
|
+
|
151
|
+
# clearbit icons
|
152
|
+
def clearbit_icon(icon, color, options = {})
|
153
|
+
image_tag "clearbits/#{icon}.gif", {:class => "clearbits #{color}", :alt => icon}.merge(options)
|
154
|
+
end
|
155
|
+
|
156
|
+
# pixel spacing helper
|
157
|
+
def pixel(options = {})
|
158
|
+
image_tag "pixel.png", options
|
159
|
+
end
|
160
|
+
|
161
|
+
# check to see if an index is the first item in a collection
|
162
|
+
def is_first(i)
|
163
|
+
i.to_i.zero? ? {:class => "first"} : {}
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
data/spec/viewfu_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb_viewfu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jacques Crocker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-22 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.0"
|
24
|
+
version:
|
25
|
+
description: View Helpers for Title, Meta tags, Browser Detect, and Common Tag Helpers
|
26
|
+
email: merbjedi@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- Rakefile
|
38
|
+
- lib/browser_detect
|
39
|
+
- lib/browser_detect/helper.rb
|
40
|
+
- lib/headliner
|
41
|
+
- lib/headliner/helper.rb
|
42
|
+
- lib/headliner/README
|
43
|
+
- lib/merb_viewfu.rb
|
44
|
+
- lib/view_fu
|
45
|
+
- lib/view_fu/meta_helper.rb
|
46
|
+
- lib/view_fu/tag_helper.rb
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
- spec/viewfu_spec.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://merbjedi.com/
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: merb
|
71
|
+
rubygems_version: 1.3.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 2
|
74
|
+
summary: View Helpers for Title, Meta tags, Browser Detect, and Common Tag Helpers
|
75
|
+
test_files: []
|
76
|
+
|