Setting Defaults?

4 views
Skip to first unread message

Michael

unread,
Apr 24, 2008, 3:52:01 PM4/24/08
to Webby
Is there a way to set some site-wide default variables, such as in the
layout template and then reference those in the individual pages?

For example, I tried the following in layouts/default.rhtml I tried to
add the following:

---
extension: html
filter: erb

company: "My Company"
email: "ema...@here.com"
phone: "555.123.4567"
---

And then in a template file, reference them something along these
lines:

<h1>Welcome to <%= @page.company %></h1>
Contact me at: <%= @page.phone %>

Regards,

Michael

Bruce Williams

unread,
Apr 24, 2008, 4:28:19 PM4/24/08
to webby...@googlegroups.com

Michael,

If you set SITE attribute in your Rakefile they should be available
under Webby.site in your pages.

For example, I have the following set it my Rakefile:

SITE.create_mode = 'directory'
SITE.uv = { :theme => 'blackboard' }

These are available as Webby.site.create_mode and Webby.site.uv in my
templates & helpers.

Cheers,
Bruce

---
Bruce Williams
http://codefluency.com
twitter: wbruce

Tim Pease

unread,
Apr 24, 2008, 9:02:47 PM4/24/08
to webby...@googlegroups.com
On Apr 24, 2008, at 1:52 PM, Michael wrote:

>
> Is there a way to set some site-wide default variables, such as in the
> layout template and then reference those in the individual pages?
>

The layouts have access to a page's meta-data, but a page does not
have access to the layout's meta-data.

However, you can set page defaults that will be used for every page in
your site. The following snippet of code would go in your site
Rakfile ...

SITE.page_defaults = {
'layout' => 'default',
'company' => 'My Company',
'email' => 'em...@example.com',
'phone' => '555.123.4567'
}

All your pages will have those as default values now. The
"page_defaults" hash already exists, and that is how the "default"
layout is selected for all the pages in a site. So you don't have to
create a new hash; you can just add new key/value pairs to the
existing page_defaults.

SITE.page_defaults['key'] = 'value'

Your ERB snippet below should work with these defaults defined.

FYI -- if you change the defaults in the Rakefile, you'll have to run
"rake rebuild" for all the pages to regenerate.

Blessings,
TwP

>
> And then in a template file, reference them something along these
> lines:
>
> <h1>Welcome to <%= @page.company %></h1>
> Contact me at: <%= @page.phone %>
>


PS Here is everything that currently exists in the SITE struct ...

# call-seq:
# Webby.site => struct
#
# Returns a struct containing the configuration parameters for the
# Webby site. These defaults should be overridden as needed in the
# site specific Rakefile.
#
def self.site
return @site if defined? @site
@site = OpenStruct.new(
:output_dir => 'output',
:content_dir => 'content',
:layout_dir => 'layouts',
:template_dir => 'templates',
:exclude => %w(tmp$ bak$ ~$ CVS \.svn),
:page_defaults => {
'layout' => 'default'
},
:find_by => 'title',
:base => nil,
:create_mode => 'page',
:blog_dir => 'blog',

# Items for running the heel webserver
:heel_port => 4331,

# Items used to deploy the website
:host => 'us...@hostname.tld',
:remote_dir => '/not/a/valid/dir',
:rsync_args => %w(-av --delete),

# Options passed to the 'tidy' program when the tidy filter is
used
:tidy_options => '-indent -wrap 80',

# List of valid URIs (these automatically pass validation)
:valid_uris => [],

# Options for coderay processing
:coderay => {
:lang => :ruby,
:line_numbers => nil,
:line_number_start => 1,
:bold_every => 10,
:tab_width => 8
},

# Options for graphviz processing
:graphviz => {
:path => nil,
:cmd => 'dot',
:type => 'png'
},

# Options for tex2img processing
:tex2img => {
:path => nil,
:type => 'png',
:bg => 'white',
:fg => 'black',
:resolution => '150x150'
},

# Options for ultraviolet syntax highlighting
:uv => {
:lang => 'ruby',
:line_numbers => false,
:theme => 'mac_classic'
},

# XPath identifiers used by the basepath filter
:xpaths => %w(
/html/head//base[@href]
/html/head//link[@href]
//script[@src]
/html/body[@background]
/html/body//a[@href]
/html/body//object[@data]
/html/body//img[@src]
/html/body//area[@href]
/html/body//form[@action]
/html/body//input[@src]
)
# other possible XPaths to include for base path substitution
# /html/body//object[@usemap]
# /html/body//img[@usemap]
# /html/body//input[@usemap]
)
end

Michael

unread,
Apr 25, 2008, 8:22:24 AM4/25/08
to Webby
Rock 'n Roll! Works just fine.

Thanks,

Michael
> :host => 'u...@hostname.tld',
Reply all
Reply to author
Forward
0 new messages