Module: Thoth

### Home Classes Methods

### In Files

- lib/thoth/config.rb
- lib/thoth/controller/admin.rb
- lib/thoth/controller/api/comment.rb
- lib/thoth/controller/api/page.rb
- lib/thoth/controller/api/post.rb
- lib/thoth/controller/api/tag.rb
- lib/thoth/controller/archive.rb
- lib/thoth/controller/comment.rb
- lib/thoth/controller/main.rb
- lib/thoth/controller/media.rb
- lib/thoth/controller/minify.rb
- lib/thoth/controller/page.rb
- lib/thoth/controller/post.rb
- lib/thoth/controller/search.rb
- lib/thoth/controller/tag.rb
- lib/thoth/errors.rb
- lib/thoth/helper/pagination.rb
- lib/thoth/importer.rb
- lib/thoth/model/comment.rb
- lib/thoth/model/media.rb
- lib/thoth/model/page.rb
- lib/thoth/model/post.rb
- lib/thoth/model/tag.rb
- lib/thoth/model/tags_posts_map.rb
- lib/thoth/plugin/thoth_delicious.rb
- lib/thoth/plugin/thoth_flickr.rb
- lib/thoth/plugin/thoth_tags.rb
- lib/thoth/plugin/thoth_twitter.rb
- lib/thoth/plugin.rb
- lib/thoth/version.rb
- lib/thoth.rb

### Namespace

- MODULE Thoth::Config
- MODULE Thoth::Plugin
- CLASS Thoth::AdminController
- CLASS Thoth::ArchiveController
- CLASS Thoth::Comment
- CLASS Thoth::CommentApiController
- CLASS Thoth::CommentController
- CLASS Thoth::Error
- CLASS Thoth::Importer
- CLASS Thoth::MainController
- CLASS Thoth::Media
- CLASS Thoth::MediaController
- CLASS Thoth::MinifyController
- CLASS Thoth::Page
- CLASS Thoth::PageApiController
- CLASS Thoth::PageController
- CLASS Thoth::Pager
- CLASS Thoth::Post
- CLASS Thoth::PostApiController
- CLASS Thoth::PostController
- CLASS Thoth::SchemaError
- CLASS Thoth::SearchController
- CLASS Thoth::Tag
- CLASS Thoth::TagApiController
- CLASS Thoth::TagController
- CLASS Thoth::TagsPostsMap

### Methods

- ::create
- ::init_ramaze
- ::init_thoth
- ::open_db
- ::restart
- ::run
- ::start
- ::stop

### Files

- robots.txt

### Class/Module Index

Quicksearch

- Thoth
- Thoth::AdminController
- Thoth::ArchiveController
- Thoth::Comment
- Thoth::CommentApiController
- Thoth::CommentController
- Thoth::Config
- Thoth::Error
- Thoth::Importer
- Thoth::MainController
- Thoth::Media
- Thoth::MediaController
- Thoth::MinifyController
- Thoth::Page
- Thoth::PageApiController
- Thoth::PageController
- Thoth::Pager
- Thoth::Plugin
- Thoth::Plugin::Delicious
- Thoth::Plugin::Flickr
- Thoth::Plugin::Tags
- Thoth::Plugin::Twitter
- Thoth::Post
- Thoth::PostApiController
- Thoth::PostController
- Thoth::SchemaError
- Thoth::SearchController
- Thoth::Tag
- Thoth::TagApiController
- Thoth::TagController
- Thoth::TagsPostsMap
- Ramaze
- Ramaze::Dispatcher
- Ramaze::Dispatcher::File
- Ramaze::Helper
- Ramaze::Helper::Admin
- Ramaze::Helper::Cookie
- Ramaze::Helper::Error
- Ramaze::Helper::Pagination
- Ramaze::Helper::Sanitize
- Ramaze::Helper::Wiki
- Ramaze::Helper::Ysearch
- Ramaze::Helper::Ysearch::SearchError
- AddMediaSize
- CreateSchema
- PantsImporter
- PoseidonImporter

No matching classes.

# Thoth

The main Thoth namespace.

### Constants

APP_AUTHOR
APP_COPYRIGHT
APP_EMAIL
APP_NAME
APP_URL
APP_VERSION
HOME_DIR
LIB_DIR
PUBLIC_DIR
VIEW_DIR

### Attributes

db[R]

### Public Class Methods

create(path) click to toggle source

Creates a new Thoth home directory with a sample config file at the specified path.

    # File lib/thoth.rb, line 96
    def create(path)
      path = File.expand_path(path)

      if File.exist?(path)
        raise "specified path already exists: #{path}"
      end

      FileUtils.mkdir_p(path/:log)
      FileUtils.mkdir(path/:media)
      FileUtils.mkdir(path/:plugin)
      FileUtils.mkdir(path/:public)
      FileUtils.mkdir(path/:view)

      FileUtils.cp(LIB_DIR/'..'/:proto/'thoth.conf.sample', path/'thoth.conf')
      File.chmod(0750, path/:log)
      File.chmod(0640, path/'thoth.conf')
    end

init_ramaze() click to toggle source

Initializes Ramaze (but doesn't actually start the server).

    # File lib/thoth.rb, line 115
    def init_ramaze
      Ramaze::Global.setup(
        :root                 => LIB_DIR,
        :public_root          => PUBLIC_DIR,
        :view_root            => VIEW_DIR,
        :actionless_templates => false,
        :compile              => Config.server.compile_views
      )

      # Display a 404 error for requests that don't map to a controller or
      # action.
      Ramaze::Dispatcher::Error::HANDLE_ERROR.update({
        Ramaze::Error::NoAction     => [404, 'error_404'],
        Ramaze::Error::NoController => [404, 'error_404']
      })

      case trait[:mode]
      when :devel
        Ramaze::Global.benchmarking = true

      when :production
        Ramaze::Global.sourcereload = false

        # Log all errors to the error log file if one is configured.
        if Config.server.error_log.empty?
          Ramaze::Log.loggers = []
        else
          log_dir = File.dirname(Config.server.error_log)

          unless File.directory?(log_dir)
            FileUtils.mkdir_p(log_dir)
            File.chmod(0750, log_dir)
          end

          Ramaze::Log.loggers = [
            Ramaze::Logging::Logger::Informer.new(Config.server.error_log,
                [:error])
          ]
        end

        # Don't expose argument errors or exceptions in production mode.
        Ramaze::Dispatcher::Error::HANDLE_ERROR.update({
          ArgumentError => [404, 'error_404'],
          Exception     => [500, 'error_500']
        })

      else
        raise "Invalid mode: #{trait[:mode]}"
      end

      Ramaze::Global.console = trait[:irb]
    end

init_thoth() click to toggle source

Opens a connection to the Thoth database and loads helpers, controllers, models and plugins.

    # File lib/thoth.rb, line 170
    def init_thoth
      trait[:ip]   ||= Config.server.address
      trait[:port] ||= Config.server.port

      Ramaze::Log.info "Thoth home: #{HOME_DIR}"
      Ramaze::Log.info "Thoth lib : #{LIB_DIR}"

      open_db

      unless @db.table_exists?(:posts)
        raise SchemaError, "Database schema is missing or out of date. " <<
            "Please run `thoth --migrate`."
      end

      acquire LIB_DIR/:helper/'*'
      require LIB_DIR/:controller/:post # must be loaded first
      acquire LIB_DIR/:controller/'*'
      acquire LIB_DIR/:controller/:api/'*'
      acquire LIB_DIR/:model/'*'

      # Use Erubis as the template engine for all controllers.
      Ramaze::Global.mapping.values.each do |controller|
        controller.trait[:engine] = Ramaze::Template::Erubis
      end

      # If minification is enabled, intercept CSS/JS requests and route them to
      # the MinifyController.
      if Config.server.enable_minify
        Ramaze::Rewrite[/^\/(css|js)\/(.+)$/] = '/minify/%s/%s'
      end

      Config.plugins.each {|plugin| Plugin.load(plugin)}
    end

open_db() click to toggle source

Opens a Sequel database connection to the Thoth database.

    # File lib/thoth.rb, line 205
    def open_db
      if Config.db =~ /^sqlite:\/{3}(.+)$/
        dir = File.dirname($1)
        FileUtils.mkdir_p(dir) unless File.directory?(dir)
      end

      Sequel.datetime_class = Time

      @db = Sequel.open(Config.db)

      if trait[:sql_log]
        require 'logger'
        @db.logger = Logger.new(trait[:sql_log])
      end
    end

restart() click to toggle source

Restarts the running Thoth daemon (if any).

    # File lib/thoth.rb, line 222
    def restart
      stop
      sleep(1)
      start
    end

run() click to toggle source

Runs Thoth.

    # File lib/thoth.rb, line 229
    def run
      init_ramaze
      init_thoth

      Ramaze.startup(
        :force   => true,
        :adapter => trait[:adapter],
        :host    => trait[:ip],
        :port    => trait[:port]
      )
    end

start() click to toggle source

Starts Thoth as a daemon.

    # File lib/thoth.rb, line 242
    def start
      if File.file?(trait[:pidfile])
        pid = File.read(trait[:pidfile], 20).strip
        abort("thoth already running? (pid=#{pid})")
      end

      puts "Starting thoth."

      fork do
        Process.setsid
        exit if fork

        File.open(trait[:pidfile], 'w') {|file| file << Process.pid}
        at_exit {FileUtils.rm(trait[:pidfile]) if File.exist?(trait[:pidfile])}

        Dir.chdir(HOME_DIR)
        File.umask(0000)

        STDIN.reopen('/dev/null')
        STDOUT.reopen('/dev/null', 'a')
        STDERR.reopen(STDOUT)

        run
      end
    end

stop() click to toggle source

Stops the running Thoth daemon (if any).

    # File lib/thoth.rb, line 269
    def stop
      unless File.file?(trait[:pidfile])
        abort("thoth not running? (check #{trait[:pidfile]}).")
      end

      puts "Stopping thoth."

      pid = File.read(trait[:pidfile], 20).strip
      FileUtils.rm(trait[:pidfile]) if File.exist?(trait[:pidfile])
      pid && Process.kill('TERM', pid.to_i)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.