From b60ffa8f5880bd33b122a5b3bb0f283f8ac5c42a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 21 Mar 2010 13:17:04 -0400 Subject: [PATCH] initial commit --- Manifest | 5 +++ Rakefile | 18 ++++++++++ bin/trivialize | 24 ++++++++++++++ dist/htaccess.dist | 9 +++++ lib/trivial.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++ trivial.gemspec | 38 +++++++++++++++++++++ 6 files changed, 177 insertions(+) create mode 100644 Manifest create mode 100644 Rakefile create mode 100755 bin/trivialize create mode 100644 dist/htaccess.dist create mode 100644 lib/trivial.php create mode 100644 trivial.gemspec diff --git a/Manifest b/Manifest new file mode 100644 index 0000000..5ed260d --- /dev/null +++ b/Manifest @@ -0,0 +1,5 @@ +Manifest +Rakefile +bin/trivialize +dist/htaccess.dist +lib/trivial.php diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e5b575c --- /dev/null +++ b/Rakefile @@ -0,0 +1,18 @@ +require 'rubygems' +require 'rake' +require 'echoe' + +Echoe.new('trivial', '0.0.1') 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 + 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. + EOT + p.author = "John Bintz" + p.email = "john@coswelproductions.com" + p.url = "http://github.com/johnbintz/trivial" +end diff --git a/bin/trivialize b/bin/trivialize new file mode 100755 index 0000000..141d9a2 --- /dev/null +++ b/bin/trivialize @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby +require 'fileutils' + +if !ARGV[0] + puts "Please specify the name of a new directory to create & trivialize" + exit 1 +end + +puts "Trivializing #{ARGV[0]}" +FileUtils.mkdir ARGV[0] if (!File.directory? ARGV[0]) +%w{content actions views scripts styles lib}.each do |dir| + 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 +end + +puts "Done! Make sure you can use .htaccess files in your Webserver setup." diff --git a/dist/htaccess.dist b/dist/htaccess.dist new file mode 100644 index 0000000..646bd2d --- /dev/null +++ b/dist/htaccess.dist @@ -0,0 +1,9 @@ +RewriteEngine On + +RewriteRule ^$ lib/trivial.php [L] + +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !.*\.inc$ +RewriteRule /(.*) lib/trivial.php [L] + diff --git a/lib/trivial.php b/lib/trivial.php new file mode 100644 index 0000000..9046c15 --- /dev/null +++ b/lib/trivial.php @@ -0,0 +1,83 @@ +'); +} + +function scripts($additional = array()) { + return head_component($additional, 'scripts/%s.js', ''); +} + +function head_component($additional, $search, $format) { + global $requested; + + $output = array(); + foreach (array_merge(array('application', $requested), $additional) as $file) { + if (fe_check(sprintf($search, $file)) !== false) { + $output[] = sprintf($format, $file); + } + } + return implode("\n", $output); +} + +$content = null; +if (($content_file = fe_check('content/' . $requested . '.html')) !== false) { + $content = file_get_contents($content_file); +} + +foreach (array('application', $requested) as $action) { + if (($action_file = fe_check('actions/' . $action . '.inc')) !== false) { + include($action_file); + } +} + +if (($view_file = fe_check('views/' . $requested . '.inc')) !== false) { + ob_start(); + include($view_file); + $content = ob_get_clean(); +} + +if (is_null($content)) { + trigger_error("No content generated for ${requested}! Did you create a content, action, or view file for this request?"); +} + +if (($layout_file = fe_check('views/' . $layout . '.inc')) !== false) { + ob_start(); + include($layout_file); + $content = ob_get_clean(); +} + +echo $content; diff --git a/trivial.gemspec b/trivial.gemspec new file mode 100644 index 0000000..b189bad --- /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.1" + + 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", "dist/htaccess.dist", "lib/trivial.php", "trivial.gemspec"] + s.homepage = %q{http://github.com/johnbintz/trivial} + s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trivial"] + 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