biblesearch / lib / Biblesearch.pm /
Newer Older
53 lines | 0.993kb
add files
Yuki Kimoto authored on 2014-03-26
1
package Biblesearch;
2

            
3
our $VERSION = '0.01';
4

            
5
use Mojo::Base 'Mojolicious';
6
use DBIx::Custom;
7

            
8
has 'dbi';
9

            
10
sub startup {
11
  my $self = shift;
12
  
13
  # DBI
14
  my $db_file = $self->home->rel_file('db/bible.db');
15
  my $dbi = DBIx::Custom->connect(
16
    dsn =>  "dbi:SQLite:dbname=$db_file",
17
    option => {sqlite_unicode => 1},
18
    connector => 1
19
  );
20
  $self->dbi($dbi);
21
  
22
  # Models
23
  my $models = [
24
    {
25
      table => 'book',
26
      primary_key => 'id'
27
    },
28
    {
29
      table => 'section',
30
      primary_key => [qw/book_id chapter section/]
31
    }
32
  ];
33
  $dbi->create_model($_) for @$models;
34
  
35
  # Route
36
  my $r = $self->routes;
37
  $r->get('/')->to(template => 'index');
文字列の置換をjavascript側で行うようにした。
Yuki Kimoto authored on 2014-03-29
38
  $r->get('/api/book/:id/content')->to(cb => sub {
39
    my $self = shift;
40
    my $id = $self->param('id');
41
    
42
    my $dbi = $self->app->dbi;
43
    my $content = $dbi->model('book')->select('content', id => $id)->value;
44
    
45
    my $data = {
46
      content => $content
47
    };
48
    
49
    $self->render(json => $data);
50
  });
add files
Yuki Kimoto authored on 2014-03-26
51
}
52

            
53
1;