From 3b3242142853835ff727f7b2d3cf772f237e4a31 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 21 Mar 2010 15:10:08 -0400 Subject: [PATCH] more changes --- Manifest | 5 +++++ Rakefile | 2 +- bin/trivialize | 15 ++++++++------- content/index.html | 5 +++++ lib/trivial.php | 4 ++-- readme.md | 37 +++++++++++++++++++++++++++++++++++++ styles/application.css | 7 +++++++ trivial.gemspec | 38 ++++++++++++++++++++++++++++++++++++++ views/application.inc | 10 ++++++++++ 9 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 content/index.html create mode 100644 readme.md create mode 100644 styles/application.css create mode 100644 trivial.gemspec create mode 100644 views/application.inc diff --git a/Manifest b/Manifest index 5ed260d..a0fb20f 100644 --- a/Manifest +++ b/Manifest @@ -1,5 +1,10 @@ Manifest Rakefile bin/trivialize +content/index.html dist/htaccess.dist lib/trivial.php +readme.md +styles/application.css +trivial.gemspec +views/application.inc diff --git a/Rakefile b/Rakefile index 03b22b0..dd0c6a1 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require 'rubygems' require 'rake' 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.description = <<-EOT For those who are using PHP to build their sites and want a very simple framework diff --git a/bin/trivialize b/bin/trivialize index 141d9a2..b668a67 100755 --- a/bin/trivialize +++ b/bin/trivialize @@ -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)) 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')) - -if !File.exists? File.join(ARGV[0], 'content', 'index.html') - File.open File.join(ARGV[0], 'content', 'index.html'), "w" do |fh| - fh.puts %{Your Website construction work just became trivial!} - end +[ + [ [File.dirname(__FILE__), '..', 'lib', 'trivial.php'], [ARGV[0], 'lib', 'trivial.php'] ], + [ [File.dirname(__FILE__), '..', 'dist', 'htaccess.dist'], [ARGV[0], '.htaccess'] ], + [ [File.dirname(__FILE__), '..', 'views', 'application.inc'], [ARGV[0], 'views', 'application.inc'] ], + [ [File.dirname(__FILE__), '..', 'content', 'index.html'], [ARGV[0], 'content', 'index.html'] ], + [ [File.dirname(__FILE__), '..', 'styles', 'application.css'], [ARGV[0], 'styles', 'application.css'] ] +].each do |src, dest| + FileUtils.cp(File.join(*src), File.join(*dest)) end puts "Done! Make sure you can use .htaccess files in your Webserver setup." diff --git a/content/index.html b/content/index.html new file mode 100644 index 0000000..c5c6d95 --- /dev/null +++ b/content/index.html @@ -0,0 +1,5 @@ +

Welcome to Trivial

+ +

+ Buiding your site has now become trivial! +

diff --git a/lib/trivial.php b/lib/trivial.php index 3a90a14..e3f0ee9 100644 --- a/lib/trivial.php +++ b/lib/trivial.php @@ -39,11 +39,11 @@ $requested = preg_replace('#/$#', '/index.html', $_SERVER['REDIRECT_URL']); $requested = preg_replace("#${trim}/(.*)\.[^\.]+\$#", '\1', $requested); function styles($additional = array()) { - return head_component($additional, 'styles/%s.css', ''); + return head_component($additional, 'styles/%s.css', ''); } function scripts($additional = array()) { - return head_component($additional, 'scripts/%s.js', ''); + return head_component($additional, 'scripts/%s.js', ''); } function head_component($additional, $search, $format) { diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c8e5238 --- /dev/null +++ b/readme.md @@ -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. diff --git a/styles/application.css b/styles/application.css new file mode 100644 index 0000000..9da9c19 --- /dev/null +++ b/styles/application.css @@ -0,0 +1,7 @@ +* { + font-family: helvetica, arial +} + +body { + background-color: #eee +} diff --git a/trivial.gemspec b/trivial.gemspec new file mode 100644 index 0000000..5c9155a --- /dev/null +++ b/trivial.gemspec @@ -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 diff --git a/views/application.inc b/views/application.inc new file mode 100644 index 0000000..afe6e79 --- /dev/null +++ b/views/application.inc @@ -0,0 +1,10 @@ + + + My Application + + + + + + +