trivial 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ Rakefile
3
+ bin/trivialize
4
+ dist/htaccess.dist
5
+ lib/trivial.php
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('trivial', '0.0.2') do |p|
6
+ p.summary = "Ultra-lightweight website framework for PHP"
7
+ p.description = <<-EOT
8
+ For those who are using PHP to build their sites and want a very simple framework
9
+ in which to organize their files, trivial is the solution. It's one PHP file
10
+ that can include a few other pre-determined PHP and HTML files based on the
11
+ request URI. This very simple division of content, actions (controllers), and
12
+ views allows for multiple people to easily work on a smaller project without
13
+ the overhead of a larger framework.
14
+ EOT
15
+ p.author = "John Bintz"
16
+ p.email = "john@coswelproductions.com"
17
+ p.url = "http://github.com/johnbintz/trivial"
18
+ end
data/bin/trivialize ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ if !ARGV[0]
5
+ puts "Please specify the name of a new directory to create & trivialize"
6
+ exit 1
7
+ end
8
+
9
+ puts "Trivializing #{ARGV[0]}"
10
+ FileUtils.mkdir ARGV[0] if (!File.directory? ARGV[0])
11
+ %w{content actions views scripts styles lib}.each do |dir|
12
+ FileUtils.mkdir File.join(ARGV[0], dir) if (!File.directory? File.join(ARGV[0], dir))
13
+ end
14
+
15
+ FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'lib', 'trivial.php'), File.join(ARGV[0], 'lib', 'trivial.php'))
16
+ FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'dist', 'htaccess.dist'), File.join(ARGV[0], '.htaccess'))
17
+
18
+ if !File.exists? File.join(ARGV[0], 'content', 'index.html')
19
+ File.open File.join(ARGV[0], 'content', 'index.html'), "w" do |fh|
20
+ fh.puts %{Your Website construction work just became <a href="http://github.com/johnbintz/trivial/">trivial</a>!}
21
+ end
22
+ end
23
+
24
+ puts "Done! Make sure you can use .htaccess files in your Webserver setup."
@@ -0,0 +1,9 @@
1
+ RewriteEngine On
2
+
3
+ RewriteRule ^$ lib/trivial.php [L]
4
+
5
+ RewriteCond %{REQUEST_FILENAME} !-d
6
+ RewriteCond %{REQUEST_FILENAME} !-f
7
+ RewriteCond %{REQUEST_FILENAME} !.*\.inc$
8
+ RewriteRule /(.*) lib/trivial.php [L]
9
+
data/lib/trivial.php ADDED
@@ -0,0 +1,88 @@
1
+ <?php
2
+
3
+ // If you're using a different global default layout name, change it here
4
+ $layout = 'application';
5
+
6
+ if (!isset($_SERVER['REDIRECT_URL'])) {
7
+ header('HTTP/1.1 403 Forbidden');
8
+ exit(1);
9
+ }
10
+
11
+ // END OF USER-CONFIGURABLE SETTINGS
12
+
13
+ function fe_check($path) {
14
+ global $root_dir;
15
+ if (file_exists($full_path = ($root_dir . '/' . $path))) {
16
+ return $full_path;
17
+ } else {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ function partial($name, $local = array()) {
23
+ $name = preg_replace('#/([^/]+)$', '/_\1', $name);
24
+ if (($path = fe_check('views/' . $name . '.inc')) !== false) {
25
+ extract($local);
26
+ ob_start();
27
+ include($path);
28
+ return ob_get_clean();
29
+ } else {
30
+ trigger_error("No partial named ${name} found!");
31
+ }
32
+ }
33
+
34
+ $root_dir = realpath(dirname(__FILE__) . '/../');
35
+
36
+ $trim = str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath($root_dir));
37
+
38
+ $requested = preg_replace('#/$#', '/index.html', $_SERVER['REDIRECT_URL']);
39
+ $requested = preg_replace("#${trim}/(.*)\.[^\.]+\$#", '\1', $requested);
40
+
41
+ function styles($additional = array()) {
42
+ return head_component($additional, 'styles/%s.css', '<link rel="stylesheet" href="%s" type="text/css" />');
43
+ }
44
+
45
+ function scripts($additional = array()) {
46
+ return head_component($additional, 'scripts/%s.js', '<script type="text/javascript" src="%s"></script>');
47
+ }
48
+
49
+ function head_component($additional, $search, $format) {
50
+ global $requested;
51
+
52
+ $output = array();
53
+ foreach (array_merge(array('application', $requested), $additional) as $file) {
54
+ if (fe_check(sprintf($search, $file)) !== false) {
55
+ $output[] = sprintf($format, $file);
56
+ }
57
+ }
58
+ return implode("\n", $output);
59
+ }
60
+
61
+ $content = null;
62
+ if (($content_file = fe_check('content/' . $requested . '.html')) !== false) {
63
+ $content = file_get_contents($content_file);
64
+ }
65
+
66
+ foreach (array('application', $requested) as $action) {
67
+ if (($action_file = fe_check('actions/' . $action . '.inc')) !== false) {
68
+ include($action_file);
69
+ }
70
+ }
71
+
72
+ if (($view_file = fe_check('views/' . $requested . '.inc')) !== false) {
73
+ ob_start();
74
+ include($view_file);
75
+ $content = ob_get_clean();
76
+ }
77
+
78
+ if (is_null($content)) {
79
+ trigger_error("No content generated for ${requested}! Did you create a content, action, or view file for this request?");
80
+ }
81
+
82
+ if (($layout_file = fe_check('views/' . $layout . '.inc')) !== false) {
83
+ ob_start();
84
+ include($layout_file);
85
+ $content = ob_get_clean();
86
+ }
87
+
88
+ echo $content;
data/trivial.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{trivial}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["John Bintz"]
9
+ s.date = %q{2010-03-21}
10
+ s.default_executable = %q{trivialize}
11
+ s.description = %q{ For those who are using PHP to build their sites and want a very simple framework
12
+ in which to organize their files, trivial is the solution. It's one PHP file
13
+ that can include a few other pre-determined PHP and HTML files based on the
14
+ request URI. This very simple division of content, actions (controllers), and
15
+ views allows for multiple people to easily work on a smaller project without
16
+ the overhead of a larger framework.
17
+ }
18
+ s.email = %q{john@coswelproductions.com}
19
+ s.executables = ["trivialize"]
20
+ s.extra_rdoc_files = ["bin/trivialize", "lib/trivial.php"]
21
+ s.files = ["Manifest", "Rakefile", "bin/trivialize", "dist/htaccess.dist", "lib/trivial.php", "trivial.gemspec"]
22
+ s.homepage = %q{http://github.com/johnbintz/trivial}
23
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trivial"]
24
+ s.require_paths = ["lib"]
25
+ s.rubyforge_project = %q{trivial}
26
+ s.rubygems_version = %q{1.3.6}
27
+ s.summary = %q{Ultra-lightweight website framework for PHP}
28
+
29
+ if s.respond_to? :specification_version then
30
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
31
+ s.specification_version = 3
32
+
33
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
34
+ else
35
+ end
36
+ else
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trivial
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - John Bintz
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-21 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: "\t\tFor those who are using PHP to build their sites and want a very simple framework\n\
22
+ \t\tin which to organize their files, trivial is the solution. It's one PHP file\n\
23
+ \t\tthat can include a few other pre-determined PHP and HTML files based on the\n\
24
+ \t\trequest URI. This very simple division of content, actions (controllers), and\n\
25
+ \t\tviews allows for multiple people to easily work on a smaller project without\n\
26
+ \t\tthe overhead of a larger framework.\n"
27
+ email: john@coswelproductions.com
28
+ executables:
29
+ - trivialize
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - bin/trivialize
34
+ - lib/trivial.php
35
+ files:
36
+ - Manifest
37
+ - Rakefile
38
+ - bin/trivialize
39
+ - dist/htaccess.dist
40
+ - lib/trivial.php
41
+ - trivial.gemspec
42
+ has_rdoc: true
43
+ homepage: http://github.com/johnbintz/trivial
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --line-numbers
49
+ - --inline-source
50
+ - --title
51
+ - Trivial
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 1
67
+ - 2
68
+ version: "1.2"
69
+ requirements: []
70
+
71
+ rubyforge_project: trivial
72
+ rubygems_version: 1.3.6
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Ultra-lightweight website framework for PHP
76
+ test_files: []
77
+