Jifty::Manual::Tutorial_zhtw(3)

NAME
Jifty::Manual::Tutorial_zhtw - Jifty XXXX

DESCRIPTION
XXXXXXXXXXXXXX jifty XXXXXXXXXXX

XXXX

  XX
XXXXXXXXXX

  XX Jifty
XXXXXX DRY ( Don't Repeat Yourself ) XXXXXXXXXX Perl X CPAN XXXXXXXXXX

Jifty XXX CPAN XXXXXXXXXXXXXXXXX 60 XXXX CPAN XXX X

XXXXXXXXXXXXXX Perl XXXXXXXXXXXXX Perl XXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Jifty XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXJifty XXXXXXXXX

XXXXXXXXXXXXXX Perl XXXX CPAN XXXXXXXXX Jifty:

  # perl -MCPAN -e"install Jifty"

XXXXXX Jifty X ".tar.gz" XXXXXXXXXXX:

  # tar xzvf jifty-<version>.tgz
  # cd jifty-<version>
  # perl Makefile.PL
  # make
  # make test
  # make install

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX "jifty-devel@lists.jifty.org" XXXXXXXXXXX XXXXXXXXXXXXXXX "GETTING HELP"

  XXXX
XXXXXX Jifty XXXXXXXXXXXXXX Jifty XXXXX

Jifty XXXXXXXXXXXXXXXXXXXXXX Jifty XXX jifty XXXXXXXXXXXXXX
 ( XXXXXXXXXXX bin/ XXXX )

XXXXXXXXXXXXXXXXXX Jifty XXXXX ( Jifty XXXXXXXXX ).

  # jifty app --name MyWeblog
  Creating new application MyWeblog
  Creating directory lib
  Creating directory lib/MyWeblog
  Creating directory bin
  Creating directory etc
  Creating directory doc
  Creating directory log
  Creating directory var
  Creating directory var/mason
  Creating directory share
  Creating directory share/po
  Creating directory share/web
  Creating directory share/web/templates
  Creating directory share/web/static
  Creating directory lib/MyWeblog/Model
  Creating directory lib/MyWeblog/Action
  Creating directory t
  Creating configuration file MyWeblog/etc/config.yml

XXXXXXXX

bin X bin/ XXXXXXX jifty, X Jifty XXXX Jifty XXXXX .

    XXXXXXXXX "schema" , XXXXXXXXXXXXXXXXX XXXX "server" , XXXXXXXXXXXXXXXX .

    XXXXX Jifty XXXXXXXXX:

        jifty help

etc XXXXXX etc/ XXXXXXXXXXXXJifty XXXXXXXXXXXXX

doc XXXXXXXXXXXXXXX doc/ XX

log Jifty XX Log::Log4perl XXXXXXXXXXXXXXXXXXX log XXXXX server.log XX error.log XXX

var Jifty XX Server XXXXXXXXXXX var XXXXXXXXXXXXXXX

share/web/po
    Jifty XXXXXX share/web/po/ XXXXXXXXXXXXX ("portable object templates") will go.

share/web/templates
    Jifty XXXXXXXX Template::Declare XXXXXXXX XXXXXX HTML::Mason XXXXX

    XXXXX Mason XXXX share/web/templates/ XXXX XXX Jifty XXX skeleton XXXXX share/web/templates/ XX

    XXXXXXXX Jifty XXXXXXXXXXXXXXXXXXXXXXXX

    XXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXX

    XXXXXXX Jifty XXXXXXXXX:

      perl -MJifty::Util -le 'print Jifty::Util->share_root'

share/web/static
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX share/web/static XXXX

    X Jifty XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    XXXJifty XX CSS XXXJavascript XXXXXXXXXXXXXXXX

    XXX Jifty share/web/static XXXXXXXXXXXXXXXXXX

lib/MyWeblog/Model
    XXXXXXXXXXXXXXXXXX "lib/MyWeblog/Model"X

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ( Data Model ) XXX

    Jifty XXXXXXXXXX ( Model Class ) XXXXXXXXXXXXXXX schemaX

    XXX Jifty XXXXXXX Jifty::Manual::ObjectModel

lib/MyWeblog/Action
    XX ( Actions ) XXXXXXXX ( Model Class ) X APIX

    XXXXXXXXXX HTML XXXXXXXXXXXXX

    Jifty XXXXXXXXXXXXXXX ( Models ) XXXXXXXXXXXX ( "CREATE" , "READ" , "UPDATE" , "DELETE" ) XX ( Actions )X

t   Jifty XXXXXXXXXXXXXXXXXXX (Model) XXXXXXXXXXXXXXXXXXXXX XXXXXXXXX t/ XXXXXXXXXXXXX

  XXXXXXXX (Data Model)
XXXXXXXXXXXXXX MyWeblog XXXXXXXXXXXXXXXXXXXX weblog XXXXX

XXXXXXXXXXXXXXXXXXXX RSS X ATOM FeedsX

XX

Weblogs XXXXXXXXXXXXXXXXXXXXXXXXXX "Post" XXXXXXX:

  # cd MyWeblog
  # jifty model --name Post
  Writing file /tmp/MyWeblog/lib/MyWeblog/Model/Post.pm
  Writing file /tmp/MyWeblog/t/00-model-Post.t

XXXXXXXXX Post XXXX ( XXXXXXXXXXXXX )X

XXXXXXXXXXX lib/MyWeblog/Model/Post.pm XXXXX

XXXXXXXXX:

  use strict;
  use warnings;

  package MyWeblog::Model::Post;
  use Jifty::DBI::Schema;

  use MyWeblog::Record schema {

  };

  # Your model-specific methods go here.

  1;

XXXXXXXXXXXXX (model class) XX

XXXXXXX "body" XX "title" XXXXXX

(XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXX ("category") XX XX ("tags") XXXXXX )

XXXXXXXXXXXXXXX

  use MyWeblog::Record schema {

XXXXX:

  column title =>
        type is 'text',
        label is 'Title',
        default is 'Untitled post';

  column body =>
        type is 'text',
        label is 'Content',
        render_as 'Textarea';

XXXXX

  XX Jifty XXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX "jifty server" XXXX Jifty XXXXXX

XXXXXXXXXXXX Jifty XXXXXXXXXXXXXXXXXXXXXXXX Jifty XXX SQLite XXXXXXXXXXXX XXXXXX PostgreSQL XX MySQL XXXXXXXXXXX etc/config.ymlX (XXX Jifty::Config XXXXXX)

    # jifty server
    WARN - Application schema has no version in the database.
    WARN - Automatically creating your database.
    INFO - Generating SQL for application MyWeblog...
    INFO - Using MyWeblog::Model::Post, as it appears to be new.
    INFO - Using Jifty::Model::Session, as it appears to be new.
    INFO - Using Jifty::Model::Metadata, as it appears to be new.
    INFO - Set up version 0.0.1, jifty version 0.81208
    INFO - You can connect to your server at http://localhost:8888/

XXXXXXXXXXXXXXXXXXXXXX XXXXXXXX Jifty XXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX AJAX XXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXX "./bin/jifty server" X

  XXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX (posts) X

XXXXXXXXXXXXXXXXXXXXXXXXXXX welogX

XX

XXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXX lib/MyWeblog/View.pm XXX XXXXXXXX:

  package MyWeblog::View;
  use strict;
  use warnings;
  use Jifty::View::Declare -base;

  template post => page { title => 'Post Entry' } content {
      my $action = new_action(class => 'CreatePost');

      form {
          render_action $action;

          # XXXX
          form_submit(label => 'Post');
      }
  };

  1;

XX

XXX XX XXXXXXXXXXXX AJAX XXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX

The quick and dirty way

XXXX lib/MyWeblog/View.pm XXXXXX "post" XX "1;" XXXXXXXXXXX:

  template '/' => page {

      # XXXXXXXX
      my $posts = MyWeblog::Model::PostCollection->new;
      $posts->unlimit;

      # XXXXXXXX <dl> HTML XXXX
      dl {
          while (my $post = $posts->next) {
              dt { $post->title }
              dd { $post->body  }
          }
      }
  };

XXXX "http://localhost:8888" XXXXXXXXXXXXXXX

XXXXXXXXXX

XX complex way XXX Jifty XXXXXXX: XXXX ( Page regions ) XXXXXXXXXXXXXXXXX AJAX XXXXXXXXXX "lynx" X "w3m" XXXXX GET XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX (template) XX XXXXXXXX (regions) XXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXX XX lib/MyWeblog/View.pm XX '/' XXXXXXXXXXXXXXXXXXXXXX:

  template '/' => page {
      render_region(
          name => 'myweblog-posts',
          path => '/fragments/page_of_posts',
      );
  };

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX "/fragments/page_of_posts"X XXXXXXXXXXX:

  template '/fragments/page_of_posts' => sub {
      # XXXXXXXXXXXXX 1
      my $page = get('page') || 1;

      # XXXXXX
      my $posts = MyWeblog::Model::PostCollection->new;
      $posts->unlimit;

      # XXXXXXXXXXXXXXXXXX
      $posts->set_page_info(
          current_page => $page,
          per_page     => 3,
      );

      # XXXXXXXXXX
      if ($posts->pager->last_page > 1) {
          p { "Page $page of " . $posts->pager->last_page }
      }

      # XXXXXXXXX
      dl {
          attr { class => 'list' };

          while (my $post = $posts->next) {
              dt { $post->title }
              dd { $post->body  }
          }
      };

      # XXXXXXX XXXXXXXXXXXXX 'page' XXXXXXXXXX
      if ($posts->pager->previous_page) {
          hyperlink(
              label => 'Previous Page',
              onclick => {
                  args => {
                      page => $posts->pager->previous_page,
                  },
              },
          );
      }

      # XXXXXX
      if ($posts->pager->next_page) {
          hyperlink(
              label => 'Next Page',
              onclick => {
                  args => {
                      page => $posts->pager->next_page,
                  },
              },
          );
      }
  };

XXXXXXXX Jifty XXXXXXXX "/post" XXXXXXXXXXXX XXXXXXXXXX "Next Page" XX "Previous Page" X AJAX XXX

XXXXXXX Javascript XXX "lynx" XXXX XXXXXXXX AJAX XXXXXXXXXXXXXXXX

XXXXXXXXXXXXXX Jifty!

XXXXXXXXXX

XXXXXXX "MyWeblog::Model::PostCollection" XXXXXXXXX PostCollection.pmX Jifty XX "Jifty::ClassLoader" XXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Jifty::ClassLoader X

  XXX
XXXXXXXXXXXXXXXXX URL XXXXXXX XXXXXXXXXXXXXXX Post XXXXXXXXXXXXXXXX

XXXXXXX Blog XXXXXXX(dispatcher)XXXXXXXXXXXXXXXX URL XXXXXXXXXXX

XXXXX "XXXXXXXXXX" XXXXXXXXXXXXXXXXX

XXXXXXXX lib/MyWeblog/Dispatcher.pm XXXXXXXXX:

  package MyWeblog::Dispatcher;
  use strict;
  use warnings;
  use Jifty::Dispatcher -base;

  before '*' => run {
      my $top = Jifty->web->navigation;
      $top->child(Home => url => '/');
      $top->child(Post => url => '/post', label => 'Post Article');
  };

  1;

XXXXXXXXXXXXXXXXX Jifty::Web::MenuX

  XXXXXXXXX (XXXXXXXXXXX)
XX Jifty XX Jifty::ClassLoader XXXXXXX MyWeblog::View::Page XXXXXXXXXXXXXXXXXX XXXXXX Jifty XXXXXXXXXXXXX XXXX MyWeblog::View::Page XXXX (override) XXXXXXXXX

XXX lib/MyWeblog/View/Page.pm XXXXXXXXXX:

    use strict;
    use warnings;
    package MyWeblog::View::Page;
    use base 'Jifty::View::Declare::Page';   # XX Jifty::View::Declare::Page
    use Jifty::View::Declare::Helpers;

    sub render_body {
        my ($self, $body_code) = @_;
        $self->render_header();
        body {

            # so that we dont show menu template here.

            $self->render_pre_content_hook();
            $body_code->();
        };
    }

    sub render_page {
        my $self = shift;
        Carp::cluck $self unless $self->content_code;
        div {

            # XXXXX Page XXXXXXXXXXXX
            # page wrapper here

            $self->content_code->();
        };
    }

    sub render_footer {
        my $self = shift;

        # XXXXXXXXXXXXXXXX
        # do what you want

        $self->SUPER::render_footer;
    }

XX MyWeblog::View::Page XXX (override) XXXXXXXXXXX Jifty::View::Declare::Page XXXXXX

  XXXXXX
XXXXXXXX Jifty XXXXXXXXXXXXXXXX XXXXXX Jifty XXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXX "jifty-devel" X mailing list XXXXXXXX Jifty XX XXXXXXXXXXXXX

XXXXX

•   XXXXXXXXXXX

    Jifty::Manual::Models

•   X Jifty XX - XX (Action)

    Jifty::Manual::Actions

•   XXXXXX

    Jifty::Manual::PageRegions

•   CSS X JS

    Jifty::Manual::UsingCSSandJS, Jifty::Manual::JavaScript

•   XXXX

    XX Jifty::Manual::TutorialRest

•   XXXX ( Continuations )

    Jifty::Manual::Continuations

•   XXXXXXXXX

    Jifty::Manual::AccessControl

•   XXXXXXXX

    Jifty::Manual::Deploying

•   XXXXXXXXXX

    Jifty::Manual::Upgrading

•   XX Jifty XXXXXXXXX

    Jifty::Manual::Cookbook

XXXX

  XXXX
"jifty" XXXXXXXXXXXX:

  jifty help

  jifty help <command>

XXXXXXXXXXX ( XXXXX "AdminMode" XXXX ) XXXXXXXXXXXXXX "XXXX" XXXXXXXX Jifty XXXXXXXX

  XXXXXX
"jifty-devel@lists.jifty.org" XXXXXXXXX Jifty XXXXXXXXXXXXXXXX

XXXXXXXXXXXXX "jifty-devel-subscribe@lists.jifty.org".

  XX Wiki
XXX wiki ! (XXXXX wiki XXXX Jifty XXXXXXXX)

XXX <http://jifty.org/>, XXXXXXX

Wiki XXXX Wifty XXXXXXXXXX Jifty Subversion XXXXXXXX

XXXX
XX Jifty XXXX (Bugs) XXX "jifty-devel@lists.jifty.org"X

XXX
XXX (c9s) ( "cornelius.howl_at_gmail.com" ) <http://oulixe.us/>