-
Notifications
You must be signed in to change notification settings - Fork 33
/
app.psgi
125 lines (102 loc) · 3.74 KB
/
app.psgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!perl
use strict;
use warnings;
use Mojolicious::Lite;
use Project::Libs;
use Plack::Builder;
use Encode qw/decode_utf8/;
use Text::Md2Inao;
use Text::Md2Inao::Builder::InDesign;
get '/' => sub {
my $self = shift;
$self->render('index', version => $Text::Md2Inao::VERSION);
};
post '/upload' => sub {
my $self = shift;
return $self->render(text => 'File is too big.', status => 200)
if $self->req->is_limit_exceeded;
return $self->redirect_to('form')
unless my $file = $self->param('markdown');
my $md = $file->slurp;
my $p = Text::Md2Inao->new({
default_list => 'disc',
max_list_length => 63,
max_inline_list_length => 53,
blank_style => $self->req->param('blank_style'),
});
if ($self->req->param('in_design')) {
my $id_builder = Text::Md2Inao::Builder::InDesign->new();
$p->builder($id_builder);
}
my @errors;
local $Text::Md2Inao::Logger::LOG = sub {
my($type, $message) = @_;
push @errors, { type => $type, message => $message };
};
$self->render(
json => {
content => $p->parse(decode_utf8 $md),
errors => \@errors,
},
format => 'json',
);
};
app->types->type(txt => "text/plain;charset=UTF-8");
app->start;
__DATA__
@@ index.html.ep
% layout 'main';
% title 'Markdown to Inao converter';
%= form_for upload => (enctype => 'multipart/form-data', id => 'form') => begin
<fieldset>
<legend>Upload Markdown</legend>
<label>Select File</label>
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input span3"><i class="icon-file fileupload-exists"></i> <span class="fileupload-preview"></span></div><span class="btn btn-file"><span class="fileupload-new">Select file</span><span class="fileupload-exists">Change</span><input type="file" name="markdown" /></span><a href="#" class="btn fileupload-exists" id="dismiss" data-dismiss="fileupload">Remove</a>
</div>
</div>
<label for='in_design' class="checkbox">
%= check_box in_design => 1, id => 'in_design', checked => 'checked'
InDesign出力
</label>
<select name="blank_style" id="blank_style">
<option value="half">空行半行アキ</option>
<option value="full">空行1行アキ</option>
</select>
<p><button type="submit" class="btn btn-primary">Convert File</button> <img src="/img/ajax-loader.gif" alt="loading" title="loading" id="indicator"></p>
</fieldset>
% end
<div id="error">
</div>
<div id="result">
<p class="text-right"><a href="" id="download">ダウンロード (Google Chromeのみ)</a></p>
<textarea id="content"></textarea>
</div>
@@ layouts/main.html.ep
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf8">
<title><%= title %></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/md2inao.css" rel="stylesheet">
</head>
<body>
<div class="container">
<a href="https://github.com/naoya/md2inao.pl"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png" alt="Fork me on GitHub"></a>
<div class="masthead">
<h3 class="muted">Markdown2Inao</h3>
</div><!-- /.masthead -->
<%= content %>
<hr />
<div class="footer">
<p class="text-right"><a href="http://github.com/naoya/md2inao.pl">Text::Md2Inao</code> <%= $version %></a> (github)</p>
</div><!-- /.footer -->
</div><!-- /.container -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/md2inao.js"></script>
</body>
</html>