Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 99aca429194423423048e29c450ab050ab2679dd 0 parents
@justinfrench authored
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64 README.textile
@@ -0,0 +1,64 @@
+h1. LovelyLayouts
+
+Here's a bunch of helpers I find myself needing every time I start up a new Rails project. Mostly, it's just some nicer DSL wrappers around the @content_for@ patterns we all use to get get content up from the view to the layout in a Rails application (for titles, etc).
+
+h2. In your view
+
+ <!-- app/views/posts/show.html.erb -->
+ <% title @post.title %>
+ <% description @post.description %>
+ <% keywords @post.tags.join(", ") %>
+ <% copyright @post.user.full_name %>
+
+h2. In your layout
+
+ <html>
+ <head>
+ <%= title_tag "optional default title here" %>
+ <%= description_tag "optional default meta description here" %>
+ <%= keywords_tag "optional default meta keywords here" %>
+ <%= copyright_tag "optional default meta copyright notice here" %>
+ </head>
+ <body>
+ ...
+ <%= yield %>
+ ...
+ </body>
+ </html>
+
+h2. And a neat trick for the @<body>@ tag
+
+A block helper for creating body tags is also in there. The @id@ is generated from @params[:controller]@ (eg "posts"), and the @class@ is generated from @params[:controller]@ name and @params[:action]@ (eg "posts show").
+
+ <% body do %>
+ ...
+ <% end %>
+
+Which pushes out something like this:
+
+ <body id="posts" class="posts show">
+ ...
+ </body>
+
+You can set the @id@ and @class@ from your views:
+
+ <% body_id "blog" %>
+ <% body_class "whatever" %>
+
+You can override the @id@ and @class@ (or any attribute of the @<body>@ tag) too:
+
+ <% body :id => "blog", :class => "whatever", :onload => "party()" do %>
+ ...
+ <% end %>
+
+
+h2. There's always a TODO List
+
+* might write some tests!
+* really should offer the usual prefix/suffix stuff that I tend to need in @<title>@ tag
+* probably try to distill the way I do tabs too
+
+
+h2. Blah blah blah blah
+
+Copyright (c) 2009 "Justin French":http://www.justinfrench.com/, released under the MIT license.
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the lovely_layouts plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the lovely_layouts plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'LovelyLayouts'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1  install.rb
@@ -0,0 +1 @@
+# Install hook code here
75 lib/lovely_layouts.rb
@@ -0,0 +1,75 @@
+module LovelyLayouts
+
+ module ContentHelpers
+
+
+ def title(string)
+ content_for(:title, string)
+ end
+
+ def title_tag(default='')
+ content_tag(:title, @content_for_title || default)
+ end
+
+
+ def description(string)
+ content_for(:description, string)
+ end
+
+ def description_tag(default='')
+ tag(:meta, :name => "description", :content => @content_for_description)
+ end
+
+
+ def keywords(string)
+ content_for(:keywords, string)
+ end
+
+ def keywords_tag(default='')
+ tag(:meta, :name => "keywords", :content => @content_for_keywords || default)
+ end
+
+
+ def copyright(string)
+ content_for(:copyright, string)
+ end
+
+ def copyright_tag(default='')
+ tag(:meta, :name => "copyright", :content => @content_for_copyright || default)
+ end
+
+
+ def body_id(string)
+ content_for(:body_id, string)
+ end
+
+ def body_class(string)
+ content_for(:body_class, string)
+ end
+
+
+ def body(*args, &block)
+ options = args.extract_options!
+ options[:class] ||= @content_for_body_class || default_body_class
+ options[:id] ||= @content_for_body_id || default_body_id
+
+ contents = capture(&block)
+
+ concat(content_tag(:body, contents, options))
+ end
+
+
+ protected
+
+ def default_body_id
+ params[:controller]
+ end
+
+ def default_body_class
+ [params[:controller], params[:action]].join(" ")
+ end
+
+
+ end
+
+end
2  rails/init.rb
@@ -0,0 +1,2 @@
+require File.join(File.dirname(__FILE__), *%w[.. lib lovely_layouts])
+ActionView::Base.send :include, LovelyLayouts::ContentHelpers
4 tasks/lovely_layouts_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :lovely_layouts do
+# # Task goes here
+# end
8 test/lovely_layouts_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class LovelyLayoutsTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
3  test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
1  uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
Please sign in to comment.
Something went wrong with that request. Please try again.