There is a new version of the Baseline Theme. In the last few days of tinkering with it and modifying it for use with this website, I noticed a small bug. The Blueprint IE reset was acting funny in conjunction with the IE8 JavaScript. I chose to make IE8.js the default with the option of including Blueprint’s reset instead. (more…)
Posts Tagged ‘web development’
Baseline Theme Version 1.0.1
Tuesday, February 16th, 2010Roll Your Own CakePHP Components
Friday, May 22nd, 2009As someone who is not formally trained as a programmer, I often understand concepts long before actually putting them into practice. Don’t Repeat Yourself (DRY) seems simple enough. Of course I don’t want to repeat myself while programming. Who wants to dig through lines of code to find a litte snippet of logic you once wrote? Still, when you’re pressed for time, sometimes you just have to Get Things Done (GTD). So best practices go through the window and you hammer out some spaghetti code so you can move on.
It’s only recently, since I’ve slowed down to finally understand how to write CakePHP Components, that I’ve realized that DRY enhances GTD. Now that I’ve got it all straight in my head, I’m a component evangelist.
At this point I’m going to assume that you’re familiar with MCV architecture and its benefits. Once in a while there’s a bit of logic that you find yourself coding into a controller that you realize you’re going to want to use in other controllers. It’s not specific to the model. That’s where components come in. They’re bits of logic that can be used by more than one controller. Let’s look at a simple one that converts mm/dd/yyyy dates to a Unix timestamp.
<?php class DateComponent extends Object { function mkTimestamp($sentdate, $senttime){ $thedate = explode('/', $sentdate); if(!empty($senttime)){ $thetime = explode(':', $senttime); $newdate = mktime($thetime[0],$thetime[1],0,$thedate[0],$thedate[1],$thedate[2]); } else { $newdate = mktime(0,0,0,$thedate[0],$thedate[1],$thedate[2]); } return $newdate; } } ?>
The function itself is not all that complicated. The thing is that I’m going to want to use this where ever I need to convert dates. Since the component is called “Date”, it’s named with the CakePHP convention for components: DateComponent. The file is called date.php and is saved in app/controllers/components.
Now we have to tell our controller(s) to use it. I’m using it across several controllers, so I’m adding it to app/app_controller.php by adding it to the $components var: var $components = array('Date');
Now I can access it in any controller like so: $tmsmp = $this->Date->mkTimestamp($thedate, $thetime);
The whole point is that components don’t have to be complex, they’re just code you want to reuse that doesn’t necessary apply to one model. They will save you time and clean up your controllers.
When Using a Grid Layout CSS Framework, Do the Math
Tuesday, December 16th, 2008I recently spent an entire weekend trying to troubleshoot why Internet Explorer 6 kept wrapping the rightmost DIV in my design to the bottom of the page when no other browser did. In my case, I was using the Blueprint CSS framework that creates twenty-four 30 pixel columns, each with a 10 pixel right margin (except the 24th column, which has no right margin), to make a nice 950-pixel wide grid. The whole purpose of using a CSS framework is that it’s supposed to protect me from exactly the sort of problem I was having where different browsers display the page differently. I spent hours trying to figure out why Blueprint was failing in this case. Finally, on Sunday evening I figured it out. The enemy was not Blueprint. The enemy was me.

Above is an approximation of the Blueprint grid. (The thirty-pixel columns are in gray and the ten-pixel right margins in white.) Read the tutorial file for details, but basically, by defining “span-16″ as the class of your DIV, you wind up with a 630 pixel DIV with a ten-pixel right margin for a total of 640 pixels. Nice and neat, and it seemed perfect in my case since the photo I wanted to place on the right was 300 pixels wide. I even had ten pixels to spare. You’re probably a lot smarter than me, so you’ve already figured it out. Unfortunately, I spent the better part of a weekend working in this problem. Finally I was reduced to counting columns and I realized there’s no way to get a 300-pixel DIV using 40 pixel columns! Firefox, Safari & higher versions of Internet Explorer were more forgiving and formatted the page as I wanted. Only Internet Explorer 6 interpreted the code strictly in this case. The other browsers corrected for my math error. I blamed Blueprint for failing and Internet Explorer 6 for misinterpreting my CSS when I was at fault all along.
Forty X 7 (span-7) = 280. Just short of my needed 300 pixels. Forty X 8 = 320. Twenty pixels too wide which left an unwanted margin on the right of my photo. When I finally figured all of this out, I was able to use a combination of Blueprint classes and my own classes to consistently format the page the way I wanted.
Lesson learned: Leverage your CSS grid framework as much as possible, but also add up your columns to your page elements don’t get pushed around the page. It may still be necessary to define your own DIVS outside of the framework.
Getting Blueprint CSS & JavaScript Libraries Into Your CakePHP Layout
Wednesday, November 26th, 2008Updated 12/3/2008
The other day I wrote about getting the Blueprint CSS framework into your Wordpress theme. If you’re developing in CakePHP, it’s even easier to link multiple style sheets and JavaScript libraries to your layout file.
<?php
$css = array('blueprint/screen', 'blueprint/ie', 'style');
$jslibraries = array('prototype', 'scriptaculous', 'jquery');
echo $html->css('blueprint/print', 'stylesheet', 'media="print"');
echo $html->css($css, 'stylesheet', 'media=”screen, projection”');
echo $javascript->link($jslibraries);
?>
Let’s take these one at a time.
$css = array('blueprint/screen', 'blueprint/ie', 'style');
CakePHP’s html helper will load any css file you specify. First, make sure the css files are in app/webroot/css. Then put any css files you want to link to your layout in an array like I have above. You might have noticed that I didn’t include print in my array. That’s because we want to add an media=”print” as a separate attribute that the other style sheets won’t have.
Once they’re loaded into your array, simply put echo $html->css($css); in the head of your layout. The output will be:
<link rel="stylesheet" type="text/css" href="/app/webroot/css/blueprint/screen.css" />
<link rel="stylesheet" type="text/css" href="/app/webroot/css/blueprint/ie.css" />
<link rel="stylesheet" type="text/css" href="/app/webroot/css/style.css" />
We still haven’t linked our print style sheet. Make sure you link the print style sheet above the others so they override it. We can add media="print" by putting this into our layout head:
echo $html->css('blueprint/print', 'stylesheet', 'media="print"');
So now:
$css = array('blueprint/screen', 'blueprint/ie', 'style');
echo $html->css('blueprint/print', 'stylesheet', 'media="print"');
echo $html->css($css, 'stylesheet', 'media=”screen, projection”');
Results in:
<link rel="stylesheet" type="text/css" href="/cvp-msi/https/app/webroot/css/blueprint/print.css" media="print" />
<link rel="stylesheet" type="text/css" href="/cvp-msi/https/app/webroot/css/blueprint/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/cvp-msi/https/app/webroot/css/blueprint/ie.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/cvp-msi/https/app/webroot/css/style.css" media="screen, projection" />
Two things to note. In $html->css($path, $attributes), the first argument is the path from app/webroot/css. The second argument is html attributes.
Linking JavaScript libraries is very similar.
$jslibraries = array('prototype', 'scriptaculous', 'jquery');
This will link to prototype.js, scriptaculous.js and jquery.js respectively as long as there in app/webroot/js.
Put echo $javascript->link($jslibraries); into the head of your layout and you’re done. You have all three JavaScript libraries at your disposal.
Other good resources:
Incorporating Blueprint CSS Into Your New Wordpress Theme
Sunday, November 23rd, 2008If you’re familiar with the Blueprint CSS framework, you already know it can make your life a lot easier. So how do you get it into your Wordpress theme? Luckily, Wordpress is designed to make your life easier too.
I’m assuming your know the basics of Wordpress Theme Development. That is, at the very least you need:
- header.php
- footer.php
- index.php
- style.css
Put those files in a folder named after your theme. And put that folder in /wordpressroot/wp-content/themes/.
Once you’ve gotten that far, download the Blueprint CSS Framework and drop the “blueprint” folder from that download into your theme’s directory.
Finally, to include the new CSS files into your theme, just add this code to your header:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/blueprint/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/blueprint/print.css" type="text/css" media="print">
<!--[if IE]>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/blueprint/ie.css" type="text/css" media="screen, projection">
<![endif]-->
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
Pay attention to the order. You want to make sure that href="<?php bloginfo('stylesheet_url'); ?>" appears last in the list of style sheets. That’s your style.css where you can tailor the CSS for your specific design.
That’s it.
Blueprint CSS Tutorial File
Saturday, November 22nd, 2008Just like the README file for Blueprint CSS, I wanted to refer to the TUTORIAL file in a more readable format. Here it is formatted for easy reading.
Blueprint CSS Framework Tutorial
Welcome to this tutorial on Blueprint. It will give you a thorough intro to what you can do with the framework, and a few notes on what you shouldn’t do with it. Let’s get started.
About Blueprint
Blueprint is a CSS framework, designed to cut down on your development time. It gives you a solid foundation to build your CSS on top of, including some sensible default typography, a customizable grid, a print stylesheet and much more.
However, BP is not a silver bullet, and it’s best suited for websites where each page may require it’s own design. Take a look at existing BP pages before deciding if the framework is right for you. You may also check out the test files in the tests directory, which demonstrates most of the features in Blueprint.
The word “framework” may be a bit misleading in this context, since BP does not make suggestions on how you should organize or write your CSS. It’s more like a “css toolbox” with helpful bits and pieces, from which you may pick and choose based on your needs.
Structural Overview
From the bottom up, here are the CSS layers in Blueprint:
- CSS reset: Removes any default CSS rules set by each browser.
- Typography: Gives you some nice default typography and colors.
- Grid: Provides a set of CSS classes for making grid layouts.
The second part of Blueprint are the scripts, which lets you customize most aspects of the framework, from column count and widths, to output paths and CSS class namespaces. We have two scripts:
- Compressor: For compressing and customizing the source files.
- Validator: For validating the Blueprint core files.
That’s the quick overview, so now we can finally get into the details. First, we’ll take a look at the CSS in Blueprint. We’ll then move on to the scripts, where I’ll show you how to customize the framework.
Setting Up Blueprint
To use Blueprint, you must include three files in your HTML:
blueprint/screen.css: All CSS for screen, projection viewing.blueprint/print.css: A basic stylesheet for printing.blueprint/ie.css: A few needed corrections for Internet Explorer
To include them, use the following HTML (make sure the href paths are correct):
<link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print">
<!--[if IE]>
<link rel="stylesheet" href="css/blueprint/ie.css" type="text/css" media="screen, projection">
<![endif]-->
Remember to add trailing slashes if you’re using XHTML (” />”).
Using the CSS in Blueprint
As mentioned before, there’s basically three layers of CSS in Blueprint. The first two layers, the browser CSS reset and the default typography, apply themselves by changing CSS of standard HTML elements.
In other words, you don’t need to change anything in these files. If you for instance want to change the font size, do this in your own stylesheet, so that it’s easy to upgrade Blueprint when new versions arrive.
Classes for Typography
While the typography of Blueprint mainly applies itself, there’s a few classes provided. Here’s a list of their names and what they do:
.small- Makes the text of this element smaller.
.large- Makes the text of this element larger.
.hide- Hides an element.
.quiet- Tones down the font color for this element.
.loud- Makes this elements text black.
.highlight- Adds a yellow background to the text.
.added- Adds green background to the text.
.removed- Adds red background to the text.
.first- Removes any left sided margin/padding from the element.
.last- Removes any right sided margin/padding from the element.
.top- Removes any top margin/padding from the element.
.bottom- Removes any bottom margin/padding from the element.
Styling Forms
To make Blueprint style your input elements, each text input element should have the class .text, or .title, where .text is the normal size, and .title gives you an input field with larger text.
There’s also a few classes you may use for success and error messages:
div.error- Creates an error box (red).
div.notice- Creates a box for notices (yellow).
div.success- Creates a box for success messages (green).
Creating a Grid
The third layer is the grid CSS classes, which is the tool Blueprint gives you to create almost any kind of grid layout for your site. Keep in mind that most of the CSS behind the grid can be customized (explained below). In this section however, I’m using the default settings.
The default grid is made up of 24 columns, each spanning 30px, with a 10px margin between each column. The total width comes to 950px, which is a good width for 1024×768 resolution displays. If you’re interested in a narrower design, see the section on customizing the grid, below.
So how do you set up a grid? By using classes provided by Blueprint. To create a column, make a new <div>, and apply one of the .span-x classes to it. For instance, if you want a 3-column setup, with two narrow and one wide column, a header and a footer here’s how you do it:
<div class="container">
<div class="span-24">
The header
</div>
<div class="span-4">
The first column
</div>
<div class="span-16">
The center column
</div>
<div class="span-4 last">
The last column
</div>
<div class="span-24">
The footer
</div>
</div>
In addition to the spans, there are two important classes you need to know about. First of all, every Blueprint site needs to be wrapped in a div with the class .container, which is usually placed right after the body tag.
Second, the last column in a row (which by default has 24 columns), needs the class .last to remove its left hand margin. Note, however, that each .span-24 don’t need the .last class, since these always span the entire width of the page.
To create basic grids, this is all you need to know. The grid CSS however, provides many more classes
for more intricate designs. To see some of them in action, check out the files in tests/parts/. These files demonstrate what’s possible with the grid in Blueprint.
Here’s a quick overview of the other classes you can use in to make your grid:
.append-x- Appends x number of empty columns after a column.
.prepend-x- Preppends x number of empty columns before a column.
.push-x- Pushes a column x columns to the left. Can be used to swap columns.
.pull-x- Pulls a column x columns to the right. Can be used to swap columns.
.border- Applies a border to the right side of the column.
.colborder- Appends one empty column, with a border down the middle.
.clear- Makes a column drop below a row, regardless of space.
- .showgrid
- Add to container or column to see the grid and baseline.
In this list, x is a number from 1 through 23 for append/prepend and 1 through 24 for push/pull. These numbers will of course change if you set a new number of columns in the settings file.
Here’s another example where we have four columns of equal width, with a border between the two first and the two last columns, as well as a four column gap in the middle:
<div class="container">
<div class="span-5 border">
The first column
</div>
<div class="span-5 append-4">
The second column
</div>
<div class="span-5 border">
The third column
</div>
<div class="span-5 last">
The fourth (last) column
</div>
</div>
You may also nest columns to achieve the desired layout. Here’s a setup where we want four rectangles with two on top and two below on the first half of the page, and one single column spanning the second half of the page:
<div class="container">
<div class="span-12">
<div class="span-6">
Top left
</div>
<div class="span-6 last">
Top right
</div>
<div class="span-6">
Bottom left
</div>
<div class="span-6 last">
Bottom right
</div>
</div>
<div class="span-12 last">
Second half of page
</div>
</div>
Try this code in your browser it it’s difficult to understand what it would look like. To see more examples on how to use these classes, check out /tests/parts/grid.html.
The Scripts
Blueprint comes with two scripts: one for compressing and customizing the CSS, and one for validating the core CSS files, which is handy if you’re making changes to these files.
The Validator
The validator has a fairly simple job – validate the CSS in the core BP files. The script uses a bundled version of the W3C CSS validator to accomplish this. To run it, you’ll need to have Ruby installed on your machine. You can then run the script like so: $ ruby validate.rb.
Note that there are a few validation errors shipping with Blueprint. These are known, and comes from a few CSS hacks needed to ensure consistent rendering across the vast browser field.
The Compressor
As the files you’ll include in your HTML are the compressed versions of the core CSS files, you’ll have to recompress the core if you’ve made any changes. This is what the compressor script is for.
In addition this is where you customize the grid. To customize the grid, a special settings file is used, and the new CSS is generated once you run the compressor. The new compressed files will then reflect your settings file.
To recompress, you just have to run the script. This will parse the core CSS files and output new compressed files in the blueprint folder. As with the validator, Ruby has to be installed to use this script. In the lib directory, run: $ruby compress.rb
Calling this file by itself will pull files from blueprint/src and concatenate them into three files; ie.css, print.css, and screen.css. However, argument variables can be set to change how this works. Calling $ruby compress.rb -h will reveal basic arguments you can pass to the script.
Custom Settings
To learn how to use custom settings, read through the documentation within lib/compress.rb
Blueprint CSS Readme File
Saturday, November 22nd, 2008Author’s note: This is word for word post of the Blueprint CSS file only because I’m tired of pulling up the text file and I’d rather read it in a nicely formatted HTML page. I’m sure others would prefer that too.
Blueprint CSS Framework Readme
Welcome to Blueprint! This is a CSS framework designed to cut down on your CSS development time.
It gives you a solid foundation to build your own CSS on. Here are some of the features BP provides out-of-the-box:
- An easily customizable grid
- Sensible default typography
- A typographic baseline
- Perfected browser CSS reset
- A stylesheet for printing
- Powerful scripts for customization
- Absolutely no bloat!
Project Info
Setup Instructions
Here’s how you set up Blueprint on your site.
- Upload the “blueprint” folder in this folder to your server, and place it in whatever folder you’d like. A good choice would be your CSS folder.
- Add the following three lines to every
<head/>of your site. Make sure the threehrefpaths are correct (here, BP is in my CSS folder):
<link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print">
<!--[if IE]>
<link rel="stylesheet" href="css/blueprint/ie.css" type="text/css" media="screen, projection">
<![endif]-->Remember to include trailing slashes (” />”) in these lines if you’re using XHTML.
- For development, add the .showgrid class to any container or column to see the underlying grid.
Check out the plugins directory for more advanced functionality.
Tutorials
- Tutorial on BlueFlavor
- How to customize BP with the compressor script
- How to use a grid in a layout
- How to use a baseline in your typography
Files in Blueprint
The framework has a few files you should check out. Every file in the src directory contains lots of (hopefully) clarifying comments.
Compressed files (these go in the HTML):
blueprint/screen.cssblueprint/print.cssblueprint/ie.css
Source files:
blueprint/src/reset.css
This file resets CSS values that browsers tend to set for you.blueprint/src/grid.css
This file sets up the grid (it’s true). It has a lot of classes you apply to<div/>elements to set up any sort of column-based grid.blueprint/src/typography.css
This file sets some default typography. It also has a few methods for some really fancy stuff to do with your text.blueprint/src/forms.css
Includes some minimal styling of forms.blueprint/src/print.css
This file sets some default print rules, so that printed versions of your site looks better than they usually would. It should be included on every page.blueprint/src/ie.css
Includes every hack for our beloved IE6 and 7.
Scripts:
lib/compress.rb
A Ruby script for compressing and customizing your CSS. Set a custom namespace, column count, widths, output paths, multiple projects, and semantic class names. See commenting incompress.rbor run$ruby compress.rb -hfor more information.lib/validate.rb
Validates the Blueprint core files with the W3C CSS validator.
Other:
blueprint/plugins/
Contains additional functionality in the form of simple plugins for Blueprint. See individual readme files in the directory of each plugin for further instructions.tests/
Contains html files which tests most aspects of Blueprint. Opentests/index.htmlfor further instructions.
Extra Information
- For credits and origins, see AUTHORS.
- For license instructions, see LICENSE.
- For the latest updates, see CHANGELOG.
Wow. ACL is Hard
Friday, June 20th, 2008That is Access Control Lists. I’ve been developing with CakePHP this spring and summer and it was all going very well until I actually needed to control access to the application. It’s not even that CakePHP falls short here. There are apparently tons of built-in tools for managing access. They’re just poorly documented and the community is relatively new so no one has built a complete plug in. If you’re looking for a solution like I was, I’m afraid I’m not going to give you the best answer here. I did find something that works, so read on. Especially if you’re learning ACL or Modified Preorder Tree Traversal Algorithm (MPTTA) for the first time.
Disclosure: I’m not formally trained as a programmer/developer. Everything I’ve learned, I’ve taught myself. So there are definitely some silos in my knowledge as I’ve learned things on the basis of necessity. I have, however, been developing in PHP for over six years. So it’s not all that bad.
So the learning curve for implementing ACL has been relatively steep for me. First, I had to get my head around the concept. The big picture is easy. What we’re after is a tree of access with ‘admin’ at the root and everything else branching off from that with diminishing access. That’s not hard to conceptualize. What is hard is putting that into practice.
I messed around with this for a long time before stumbling upon this tutorial about the Modified Preorder Tree Traversal Algorithm. Stop now. Read it. Come back.
Now you should understand the concepts that drive CakePHP’s ACL. Unfortunately here is also where we depart from using CakePHP’s tools. At least until a decent plug-in comes along that allows you to manage Access Request Objects (ARO) and Access Control Objects (ACO) via a good, web-based interface.
After many attempts with various solutions that are currently avaliable, I finally settled on Authake.
Pros:
- Works in CakePHP 1.2
- User, ARO & ACO adminstration is a snap
- Access control works immediately without modifying anything you’ve built in your app.
Cons:
- Installation requires you replace the entire CakePHP engine with Authake’s modified version. This will make upgrading CakePHP a lot harder.
- The developer has abandoned it in favor of developing in RoR. No hope for future versions unless the community continues development. Personally, I’d prefer a plug-in like Jeff ’s ACL Management Plugin that I could just drop right into app/plugins without replacing the entire installation. (The issue I have with Jeff’s are all listed on his “Known Bugs” list. Namely, “does not show inherited permissions, does not show full path in finder & does not have crud fields”. Unfortunately, those are three very major elements of managing ACL.)
If you are reading this in the not so distant future and someone had developed a plugin that has an admin area like Authake’s but drops into app/plugins like Jeff’s plugin, please, please let me know.
