Skip to content

Commit

Permalink
full scratch.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aska committed May 6, 2011
1 parent ce90b01 commit 21ee971
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 587 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
doc
config.json
markdown-binder-plack.tmproj
.DS_Store
7kai.psgi
7kai_local.psgi
view/diary_7kai
49 changes: 0 additions & 49 deletions README.md

This file was deleted.

106 changes: 9 additions & 97 deletions app.psgi
Original file line number Diff line number Diff line change
@@ -1,108 +1,20 @@

use strict;
use Cwd 'abs_path';
use Encode;
use File::Basename;
use File::Copy;
use File::Spec::Functions qw(abs2rel catdir catfile);
use Filesys::Notify::Simple;
use JSON;
use Path::Class;
use lib qw(lib);
use Plack::Builder;
use Plack::Request;
use Text::Xslate qw(html_builder);

my $base_dir = dirname(__FILE__);
my $doc_dir = dir(abs_path($ENV{'MARKDOWN_BINDER_DOC'} || catdir($base_dir, 'doc')));
my $cache_dir = dir(abs_path($ENV{'MARKDOWN_BINDER_CACHE'} || catdir($base_dir, 'cache')));
my $tx_dir = abs_path(catdir($base_dir, 'view'));
my $htpasswd = file(abs_path($ENV{'MARKDOWN_BINDER_PW'} || catfile($base_dir, '.htpasswd')));
my $iprules = file(abs_path($ENV{'MARKDOWN_BINDER_IP'} || catfile($base_dir, '.iprules')));
my $conf_file = file(abs_path($ENV{'MARKDOWN_BINDER_CONF'} || catfile($base_dir, 'config.json')));
my $top = 'TOP';
my $suffix = '.md';
my $watcher = catfile($base_dir, 'watcher.pl');

my $res_403 = [ 403, [ 'Content-Type' => 'text/html' ], [ '403 Forbidden.' ] ];
my $res_404 = [ 404, [ 'Content-Type' => 'text/html' ], [ '404 Not Found.' ] ];

my $tx = Text::Xslate->new(
path => [$tx_dir, $cache_dir],
module => ['Text::Xslate::Bridge::TT2Like'],
syntax => 'TTerse',
function => {
same_highlight => sub {
my ($path) = @_;
return html_builder {
my ($html) = @_;
for my $part (split '/', $path) {
next unless length $part;
$html=~s|$part|<strong>$part<\/strong>|ig;
}
$html;
}
}
}
use App::MarkdownBinder;

my $app = App::MarkdownBinder->new(
root => './doc',
suffix => '.md',
base_url => '/',
title => 'App::MarkdownBinder',
top => 'README'
);

&watch() unless $ENV{'MARKDOWN_BINDER_VIEWER'}; # can with watch standalone only.

my $app = sub {
my $req = Plack::Request->new(shift);

my $file = file($cache_dir, ($req->path eq '/' ? $top : $req->path) . '.html');
return $res_403 if grep($_ eq '..', split('/', $req->path));

my %extra_params;
unless (-f $file) {
$extra_params{is_404}++;
$extra_params{files} = decode_json(file($cache_dir, 'sidebar.json')->slurp);
}

my $conf = decode_json($conf_file->slurp);
my $is_iphone = $req->user_agent=~/iPhone/ ? 1 : 0;
my $template = $is_iphone ? 'iphone.html' : 'index.html';
my $body = $tx->render($template, {
req => $req,
conf => $conf,
cache => $file,
path => decode('utf8', $req->path),
is_iphone => $is_iphone,
%extra_params
});

my $res = $req->new_response(200);
$res->content_type('text/html; charset=UTF-8');
$res->body(encode('utf8', $body));
$res->finalize;
};

builder {
if ($ENV{REVERSEPROXY}) {
enable 'XForwardedFor', trust => [qw(127.0.0.1/8)];
}
if (-f $htpasswd) {
enable 'Auth::Htpasswd', file => $htpasswd;
}
if (-f $iprules) {
enable 'IPAddressFilter', rules => [
grep /\./, split "\n", $iprules->slurp
];
}
enable 'Static',
path => qr!^/static/!, root => './htdocs/';
enable 'Static',
path => qr!^/(?:favicon.ico|robots.txt)$!, root => './htdocs/';
enable 'Static',
path => qr!\.html$!, root => $cache_dir;
enable 'Static',
path => qr!$suffix$!, root => $doc_dir;
$app;
};

sub watch {
my $pid = fork;
return if $pid;
$ENV{'MARKDOWN_BINDER_REQUIRE'} = 1;
require $watcher;
}
1 change: 0 additions & 1 deletion config.json

This file was deleted.

3 changes: 0 additions & 3 deletions doc/TOP.md

This file was deleted.

8 changes: 0 additions & 8 deletions htdocs/static/css/iphone.css

This file was deleted.

61 changes: 14 additions & 47 deletions htdocs/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ body {
}
article, aside, dialog, figure, footer, header,
hgroup, nav, section {
display: block;

display: block;
}
blockquote, q {
quotes: none;
Expand Down Expand Up @@ -101,6 +101,8 @@ body, th, td, h1, h2, h3, h4, h5, h6, pre, input, textarea, option, div, p, dt,
html, body {
height: 100%;
}
html {
}
body {
font-size: 13px;
overflow-y: scroll;
Expand All @@ -115,102 +117,67 @@ a:hover {
}
#wrapper {
margin: 0 auto 0 auto;
padding: 60px 20px 0 20px;
padding: 0 20px 0 20px;
width: 1000px;
height: auto;
}
#wrapper:after {
content: "";
display: block;
clear: both;
content:"";
} /* clearfix */

/********** header **********/

header {
position: fixed;
top: 0;
width:100%;
height: 60px;
background-color: white;
z-index: 1;
border-bottom: 1px solid #ccc;
}

header h1 {
margin-bottom: 0px;
padding-top: 10px;
padding-bottom: 10px;
padding-top: 20px;
padding-bottom: 12px;
border-bottom: 1px solid #ccc;
width:100%;
font-family: Raleway;
font-weight: normal;
font-size: 24px;
font-size: 30px;
text-align: center;
}

/********** footer **********/

footer {
display: none;
padding: 10px 0;
border-top: 1px solid #ccc;
display: none;
text-align: center;
}

/********** aside **********/

aside {
margin-right: 0px;
padding: 20px 20px 20px 0px;
border-right: 1px solid #ccc;
position: fixed;
overflow-y: auto;
float: left;
width: 230px;
height: auto;
font-size: 110%;
}
aside nav #expand {
position: absolute;
left: 170px;
display: none;
aside nav {
}
aside nav ul {
list-style: none;
}
aside nav ul ul {
padding-left: 10px;
}
aside nav li.dir {
}
aside nav li.close {
color: #cccccc;
}
aside nav li.highlight {
color: #666666;
}
aside nav li a {
display: block;
}
aside nav li a.highlight {
background-color: #ffffdc;
}

/********** article **********/

article {
margin: 0 0 0 0;
padding: 20px;
position: relative;
float: right;
width: 705px;
position: relative;
}

/* permalink and source */

article nav {
position: absolute;
right: 0;
text-align: right;
}

/* paragraphs */
Expand Down Expand Up @@ -268,8 +235,8 @@ article pre {
article pre code {
padding: 0;
border-bottom: none;
letter-spacing: 0;
font-size: 85%;
letter-spacing: 0;
}

/* lists */
Expand Down
25 changes: 20 additions & 5 deletions htdocs/static/js/binder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
$(document).ready(function() {
var binder = new MarkdownBinder();
binder.initApplication();
});

(function(ns, w, d) {

var w = $(w);
Expand Down Expand Up @@ -45,9 +50,6 @@ function go(path, callback){
function load(path, callback){
var binder = this;
var url = path;
if (url == '/') {
url = url + 'TOP';
}
if ($.browser.msie) {
url = encodeURI(url);
}
Expand Down Expand Up @@ -101,15 +103,15 @@ function initApplication(){
if (history.pushState) {
// history.pushState('/', '', location.protocol + '//' + location.host + location.pathname);
// browser go back event
window.addEventListener('popstate', function (event) {
w.bind("popstate", function (event) {
if (binder.gone) {
binder.load(event.state);
}
});
}

// bind
$('#expand').bind('click', function(){binder.expand();return false;});
$('#expand').bind('click', function(){binder.expand()});
$('#expand').hover(function(){
$(this).css('cursor','pointer');
$(this).addClass('highlight');
Expand All @@ -118,6 +120,19 @@ function initApplication(){
$(this).removeClass('highlight');
});
$('#expand').show();
$('#close').bind('click', function(){
$('header').hide();
$('#wrapper').css('padding-top', '0');
binder.initHeight();
});
$('#close').hover(function(){
$(this).css('cursor','pointer');
$(this).addClass('highlight');
},function(){
$(this).css('cursor','default');
$(this).removeClass('highlight');
});
$('#close').show();
w.bind('resize', initHeight);

// init
Expand Down
Loading

0 comments on commit 21ee971

Please sign in to comment.