Permalink
Browse files

full scratch.

  • Loading branch information...
s-aska committed May 6, 2011
1 parent ce90b01 commit 21ee97119df23e76628f5e30928557209f69d08b
View
@@ -1,2 +1,6 @@
-doc
config.json
+markdown-binder-plack.tmproj
+.DS_Store
+7kai.psgi
+7kai_local.psgi
+view/diary_7kai
View
@@ -1,49 +0,0 @@
-# Markdown Binder
-
-Ajax Markdown Viewer written in Perl, to run under Plack.
-
-- demo: [The Document of Aska](http://doc.7kai.org)
-- source: [github](https://github.com/s-aska/markdown-binder)
-- author: [@su_aska](http://twitter.com/su_aska)
-
-## Features
-1. **High Speed** ( Ajax Page Loading and Pre Convert HTML )
-2. pushState Support
-3. no javascript Support ( bot, curl, wget...etc )
-4. **Pure Markdown** ( not extend grammar )
-5. Plack Application
-6. HTML5
-
-## Install
-
- git clone git@github.com:s-aska/app-markdown-binder-plack.git
- cd app-markdown-binder-plack
- cpanm Path::Class Text::Markdown Text::Xslate
-
-## How to use
-
-### Run
-
- plackup
- # Ctrl-C stop
-
-### Customize title and footer
-
- vi config.json
-
-### Edit page
-
- vi doc/TOP.md
- vi doc/Hoge.md
- mkdir doc/Foo
- vi doc/Foo/Bar.md
-
-## See also
-- PSGI/Plack: <http://plackperl.org/>
-- The Plack wiki: <https://github.com/miyagawa/Plack/wiki>
-- The Plack FAQ: <https://github.com/miyagawa/Plack/wiki/Faq>
-- Markdown: <http://daringfireball.net/projects/markdown/>
-- Markdown Syntax: <http://daringfireball.net/projects/markdown/syntax>
-
-## License
-Released under the [MIT license](http://creativecommons.org/licenses/MIT/).
View
106 app.psgi
@@ -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;
-}
View
@@ -1 +0,0 @@
-{"title":"please edit config.json","footer":"© please edit config.json"}
View
@@ -1,3 +0,0 @@
-# TOP
-
-... please edit this page ...
@@ -1,8 +0,0 @@
-@charset "utf-8";
-
-nav ul {
- padding-left: 1em;
-}
-nav li {
- list-style-type: none;
-}
@@ -36,8 +36,8 @@ body {
}
article, aside, dialog, figure, footer, header,
hgroup, nav, section {
- display: block;
+ display: block;
}
blockquote, q {
quotes: none;
@@ -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;
@@ -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 */
@@ -268,8 +235,8 @@ article pre {
article pre code {
padding: 0;
border-bottom: none;
- letter-spacing: 0;
font-size: 85%;
+ letter-spacing: 0;
}
/* lists */
View
@@ -1,3 +1,8 @@
+$(document).ready(function() {
+ var binder = new MarkdownBinder();
+ binder.initApplication();
+});
+
(function(ns, w, d) {
var w = $(w);
@@ -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);
}
@@ -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');
@@ -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
Oops, something went wrong.

0 comments on commit 21ee971

Please sign in to comment.