Total Pageviews

Sunday, 1 June 2014

基于php的内容生成工具-Glueprint/dummy

Brief History

Glueprint originates from a collection of very simple scripts I wrote to aid with the design, coding and testing of large-scale XHTML and CSS prototypes for newspapers and magazines. Over time, the kind of improvements I wanted to make to these scripts and helpers far surpassed my own ability to implement them - so I decided to clean up what I had cobbled together and to post the source code here. The idea being to attract some talent to the project and to have some fun in defining what a prototyping toolkit can be. Getting a better toolkit would also be nice.

Brief Philosophy

The idea with Glueprint has been to make something that the average designer or CSS nerd with a limited exposure to PHP can read, understand, and begin to hack on almost immediately - not something that can be generated .08 seconds faster or with 95% more efficiency.
Keeping glue code straightforward has the added benefit of satisfying (or at least not irritating) developers to whom you'll eventually hand over your prototype for processing into a honest-to-goodness production website. If glue code (and the patterns we build from it) can stay obvious and transparent, then hardcore developers will tend not to mind if it ends up as an aspect of your final delivery or hand-off.
In fact, when used correctly, Glueprint and glue code will help highlight for them everywhere dynamic things should be happening, and can be a great way of documenting how many items should appear in a given list, or how a submitted form should look if a user has forgotten to fill out a particular field. All of this to say that there are a lot of reasons why Glueprint favors legibility and straightforwardness over elegance or performance.
Having said that, I am definitely interested in making things easier to read and in using less code to achieve the same ends whenever possible - so long as it isn't at the expense of the code's obviousness. Your suggestions on how to create lean, beautiful glue code that is both efficient and human-readable are critical to the mission of this project. If you are into this kinda thing and want to help, consider getting involved.

from http://code.google.com/p/glueprint/wiki/About
---------------------

Getting Started with Glueprint

Download and Setup

  1. Download the latest version and extract the glueprint directory to the web root of your prototype.
  2. Give a ".php" extension to every document in which you would like to use glue code, and then add the following line to the top of the document:

    <?php require_once("glueprint/lib/glueprint.php");?>
  3. Apply glue code to your document as desired (e.g. <h1><?glue_string("headline")?></h1>)

Working with Assets

There are only two asset types currently shipping with Glueprint: strings and ads.

Strings

Strings are randomly selected bits of text containing anything from proper nouns, to date and time stamps in various forms, to chunks of Lorem Ipsum in varying lengths. The following table catalogs all of the currently available strings, a brief summary or sample of the output, and the glue code used to invoke them.
Type Location Sample Output Glue code
string assets/strings/author.string.php Célestin Sweeney <?glue_string("author")?>
string assets/strings/city.string.php Rome <?glue_string("city")?>
string assets/strings/date.string.php Tuesday, December 11th, 2007 <?glue_string("date")?>
string assets/strings/headline.string.php 5-10 words <?glue_string("headline")?>
string assets/strings/item.string.php 1-2 words <?glue_string("item")?>
string assets/strings/long_teaser.string.php 25 - 45 words <?glue_string("long_teaser")?>
string assets/strings/paragraph.string.php 2-10 sentences <?glue_string("paragraph")?>
string assets/strings/short_teaser.string.php 5-10 words <?glue_string("short_teaser")?>
string assets/strings/teaser.string.php 10-25 words <?glue_string("teaser")?>
string assets/strings/time_since.string.php 4 hours ago <?glue_string("time_since")?>
string assets/strings/time.string.php 8:58 pm <?glue_string("time")?>
string assets/strings/username.string.php zadcat <?glue_string("username")?>

Ads

The simulation of an ad server and the introduction of “real ads” into the prototyping phase can be advantageous for a number of reasons.
  • Gives you a more realistic impression of how specific elements within your design balance and compete for attention under varying commercial pressures - similar to what your site will face when it goes live.
  • Flash ads sometimes fail to play nice with a complex series of nested or floating DIV’s or can in rare cases conflict with a complex scripting technique in use on your site - and it’s better to discover it early on and get it fixed rather than trying to debug a live site.
  • Arms marketing and sales teams with valuable demo material weeks or months before an actual test or live site will come online.
Glueprint comes with a method for simulating random rotation of banner ads, as well as a library of industry standard ad formats for use in fleshing out your prototype. Ad formats are organized according to their size in a subfolder of “assets/ads”. You can use a small chunk of glue code (e.g. glue_ad(“728x90”) ) to specify the format you’d like to have inserted into your document.
The glue code used to place an ad is derived from the dimensions of the ad you wish to place, and subsequently is related to the name of the subfolder located in “assets/ads”. You can introduce a custom format by creating a subfolder named according to the dimension of the ad or ads it will contain (WIDTHxHEIGHT), and adjusting your glue code accordingly.
Glueprint will randomly select from the contents of the specified subfolder, and will embed the item into your prototype in one of two ways based on the type of asset it selects. Assets contained within a subfolder of “ads” can be of one of two types.
  • Images (.gif, .jpeg, .png, etc)
  • Flash (.swf)
The selected asset will be embedded according to the code located in two default templates located on the root of “assets/ads”.
  • image.ad.php - contains a basic <img> embed, which you can alter as needed
  • flash.ad.php - contains a standard flash <embed>, which you can alter as needed
If for some reason you need to override or alter the embed code for a specific format, place a copy of the altered template in the subfolder of the format you wish to affect. All formats will use the embed code from the default templates unless otherwise instructed.

BYOA (Bring Your Own Assets)

Remember, you can edit any of the assets to meet your needs, or create entirely new types of assets. Although not a requirement, it's recommended that every new asset type meet at least two guidelines:
  1. Located in a sub-directory of assets (e.g. "assets/strings")
  2. Maintains a naming convention across all assets of the same type (e.g. "assets/images/headline.string.php" )
Enforcing a strong and consistent naming convention across all the files of an asset type is great way of keeping things organized, and is especially important as your additions to Glueprint grow in complexity. Properly named asset files will allow you to decode the assets type, location, and the glue code needed to call it just by reading the name of the file. If the filename of your asset is really good, it will also of course tell us what it does.
Take the following example of a file named "headline.string.php".
  • headline.string.php - This probably creates a headline...
  • headline.string.php - Located in "assets/strings" (sub-folders within assets are always pluralized).
  • headline.string.php - By reading the filename backwards and using our imaginations, we can also deduce the glue code needed to place this particular asset, in this case glue_string("headline").
Another benefit of forcing assets to follow a strict naming convention is that it makes glue files easily identifiable as related to Glueprint, and less likely to be mistaken as a core part of your protoype. Not sure how important this is, but it seems like a good idea.
You can of course extend and create your own chunks of glue code in way that suits your project or particular way of working. Located in "glueprint/lib/glueprint.php" you'll find a few simple functions which map to various sub directories you might create within "glueprint/assets". Every new asset type should have a corresponding function or group of functions added to this file.

Working With Patterns

Located in "glueprint/patterns" you'll find a collection of PHP snippets which show you how to flesh out slightly more complex objects out of existing assets and glue code. They aren't anything fancy, just some starting points which can be useful an instructive in helping you to get the most out of your assets. They also underline the usefulness of maintaing a prototyping environment that can support PHP.
You should avoid embedding or including these patterns directly into your prototype, rather you should copy and paste code from these patterns into your own templates outside of your glueprint directory. This insures that the code from your prototype stays where it belongs - in your prototype - and that the examples remain intact as a reference for future use.

from http://code.google.com/p/glueprint/wiki/Usage
------------------------------
dummy - A content generation toolkit for rapid web prototyping.

from https://github.com/kerns/dummy