more changes

This commit is contained in:
John Bintz 2010-03-21 15:10:08 -04:00
parent 6e713e7b99
commit 3b32421428
9 changed files with 113 additions and 10 deletions

View File

@ -1,5 +1,10 @@
Manifest Manifest
Rakefile Rakefile
bin/trivialize bin/trivialize
content/index.html
dist/htaccess.dist dist/htaccess.dist
lib/trivial.php lib/trivial.php
readme.md
styles/application.css
trivial.gemspec
views/application.inc

View File

@ -2,7 +2,7 @@ require 'rubygems'
require 'rake' require 'rake'
require 'echoe' require 'echoe'
Echoe.new('trivial', '0.0.2') do |p| Echoe.new('trivial', '0.0.3') do |p|
p.summary = "Ultra-lightweight website framework for PHP" p.summary = "Ultra-lightweight website framework for PHP"
p.description = <<-EOT p.description = <<-EOT
For those who are using PHP to build their sites and want a very simple framework For those who are using PHP to build their sites and want a very simple framework

View File

@ -12,13 +12,14 @@ FileUtils.mkdir ARGV[0] if (!File.directory? ARGV[0])
FileUtils.mkdir File.join(ARGV[0], dir) if (!File.directory? File.join(ARGV[0], dir)) FileUtils.mkdir File.join(ARGV[0], dir) if (!File.directory? File.join(ARGV[0], dir))
end end
FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'lib', 'trivial.php'), File.join(ARGV[0], 'lib', 'trivial.php')) [
FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'dist', 'htaccess.dist'), File.join(ARGV[0], '.htaccess')) [ [File.dirname(__FILE__), '..', 'lib', 'trivial.php'], [ARGV[0], 'lib', 'trivial.php'] ],
[ [File.dirname(__FILE__), '..', 'dist', 'htaccess.dist'], [ARGV[0], '.htaccess'] ],
if !File.exists? File.join(ARGV[0], 'content', 'index.html') [ [File.dirname(__FILE__), '..', 'views', 'application.inc'], [ARGV[0], 'views', 'application.inc'] ],
File.open File.join(ARGV[0], 'content', 'index.html'), "w" do |fh| [ [File.dirname(__FILE__), '..', 'content', 'index.html'], [ARGV[0], 'content', 'index.html'] ],
fh.puts %{Your Website construction work just became <a href="http://github.com/johnbintz/trivial/">trivial</a>!} [ [File.dirname(__FILE__), '..', 'styles', 'application.css'], [ARGV[0], 'styles', 'application.css'] ]
end ].each do |src, dest|
FileUtils.cp(File.join(*src), File.join(*dest))
end end
puts "Done! Make sure you can use .htaccess files in your Webserver setup." puts "Done! Make sure you can use .htaccess files in your Webserver setup."

5
content/index.html Normal file
View File

@ -0,0 +1,5 @@
<h1>Welcome to Trivial</h1>
<p>
Buiding your site has now become <a href="http://github.com/johnbintz/trivial">trivial</a>!
</p>

View File

@ -39,11 +39,11 @@ $requested = preg_replace('#/$#', '/index.html', $_SERVER['REDIRECT_URL']);
$requested = preg_replace("#${trim}/(.*)\.[^\.]+\$#", '\1', $requested); $requested = preg_replace("#${trim}/(.*)\.[^\.]+\$#", '\1', $requested);
function styles($additional = array()) { function styles($additional = array()) {
return head_component($additional, 'styles/%s.css', '<link rel="stylesheet" href="%s" type="text/css" />'); return head_component($additional, 'styles/%s.css', '<link rel="stylesheet" href="styles/%s.css" type="text/css" />');
} }
function scripts($additional = array()) { function scripts($additional = array()) {
return head_component($additional, 'scripts/%s.js', '<script type="text/javascript" src="%s"></script>'); return head_component($additional, 'scripts/%s.js', '<script type="text/javascript" src="scripts/%s.js"></script>');
} }
function head_component($additional, $search, $format) { function head_component($additional, $search, $format) {

37
readme.md Normal file
View File

@ -0,0 +1,37 @@
# Trivial - the ultra-lightweight Web framework for PHP
## Installation
Installation is done via RubyGems:
`gem install trivial`
A new binary is created, `trivialize`.
## Creating a new site
`cd` to the directory where you want your new site and type:
`trivialize my-new-site`
A directory called `my-new-site` will be created with the site structure in place. An example `content/index.html` and `views/application.inc` will also be installed.
## The request process
When a request comes in to that directory for a file that doesn't exist, trivial
does the following (for the examples, the request was for `about_us/contact.html` and the default `$layout` value is `"application"`):
* The `content` folder is checked for a `.html` file that matches the path (`content/about_us/contact.html`). If it exists, the contents of the file are pulled into the global `$content` variable.
* The `actions` folder is checked for two files:
* `actions/application.inc`
* `actions/about_us/contact.inc`
Each found file is included into the program, potentially modifying `$content` or `$layout`.
* The `views` folder is checked for two files:
* `views/about_us/contact.inc`
* `views/application.inc`
Each found file is included into the program, including `$content` where specified and outputting back into `$content`.
* The value of `$content` is output to the visitor.
## Styles and scripts
Styles and scripts can be searched for in a structured way. The included `views/application.inc` gives an example as to how this works.

7
styles/application.css Normal file
View File

@ -0,0 +1,7 @@
* {
font-family: helvetica, arial
}
body {
background-color: #eee
}

38
trivial.gemspec Normal file
View File

@ -0,0 +1,38 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{trivial}
s.version = "0.0.3"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["John Bintz"]
s.date = %q{2010-03-21}
s.default_executable = %q{trivialize}
s.description = %q{ For those who are using PHP to build their sites and want a very simple framework
in which to organize their files, trivial is the solution. It's one PHP file
that can include a few other pre-determined PHP and HTML files based on the
request URI. This very simple division of content, actions (controllers), and
views allows for multiple people to easily work on a smaller project without
the overhead of a larger framework.
}
s.email = %q{john@coswelproductions.com}
s.executables = ["trivialize"]
s.extra_rdoc_files = ["bin/trivialize", "lib/trivial.php"]
s.files = ["Manifest", "Rakefile", "bin/trivialize", "content/index.html", "dist/htaccess.dist", "lib/trivial.php", "readme.md", "styles/application.css", "trivial.gemspec", "views/application.inc"]
s.homepage = %q{http://github.com/johnbintz/trivial}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trivial", "--main", "readme.md"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{trivial}
s.rubygems_version = %q{1.3.6}
s.summary = %q{Ultra-lightweight website framework for PHP}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
end
else
end
end

10
views/application.inc Normal file
View File

@ -0,0 +1,10 @@
<html>
<head>
<title>My Application</title>
<?php echo scripts() ?>
<?php echo styles() ?>
</head>
<body>
<?php echo $content ?>
</body>
</html>