fedwiki

package module
v0.0.0-...-0e8be2c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2015 License: MIT Imports: 17 Imported by: 0

README

Federated Wiki Server in Go

This project implements a Federated Wiki server in Go.

Installation

go get -u github.com/egonelbre/fedwiki/cmd/fedwiki
go install github.com/egonelbre/fedwiki/cmd/fedwiki

Setup

mkdir ~/tmp/fedwiki/default-pages -p && cd ~/tmp/fedwiki/

Run it

fedwiki

Notes

It does not support plugins requiring javascript server side component.

License

You may use the Wiki under either the MIT License or the GNU General Public License (GPL) Version 2.

Documentation

Overview

Package fedwiki provides tooling for Federated Wiki

See https://github.com/fedwiki for more information

Code here based on mgo/bson

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid       = errors.New("invalid argument")
	ErrPermission    = errors.New("permission denied")
	ErrNotExist      = errors.New("page does not exist")
	ErrUnknownAction = errors.New("unknown action")
)

Functions

func ErrorResponse

func ErrorResponse(ecode int, format string, args ...interface{}) (code int, template string, data interface{})

ErrorResponse creates a response based on http Error code

func NewID

func NewID() string

func ValidateSlug

func ValidateSlug(slug Slug) error

ValidateSlug verifies whether a `slug` is valid

Types

type Action

type Action map[string]interface{}

Action represents a operation that can be applied to a fedwiki.Page

func (Action) Date

func (action Action) Date() (t Date, err error)

Date returns the time when the action occurred

func (Action) Item

func (action Action) Item() (Item, bool)

Item returns the item attribute

func (Action) Str

func (action Action) Str(key string) string

Str returns string value by the key if that key doesn't exist, it will return an empty string

func (Action) Type

func (action Action) Type() string

Type returns the action type attribute

type Date

type Date struct{ time.Time }

Date represents a federated wiki time it's represented by unix time in JSON

func NewDate

func NewDate(t time.Time) Date

NewDate returns a federated wiki Date

func ParseDate

func ParseDate(data string) (Date, error)

ParseDate parses federated wiki time format

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON marshals Date as unix timestamp

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON unmarshals Date from an unix timestamp

type Handler

type Handler interface {
	Handle(r *http.Request) (code int, template string, data interface{})
}

Handler is the interface for handling federated wiki requests

type HandlerFunc

type HandlerFunc func(r *http.Request) (code int, template string, data interface{})

HandlerFunc type adapts a function to be used as a regular handler

func (HandlerFunc) Handle

func (fn HandlerFunc) Handle(r *http.Request) (code int, template string, data interface{})

type Item

type Item map[string]interface{}

Item represents a federated wiki Story item

func (Item) ID

func (item Item) ID() string

ID returns the `item` identificator

func (Item) Val

func (item Item) Val(key string) string

Val returns a string value from key

type Journal

type Journal []Action

Journal contains the history of the Page

type Meta

type Meta map[string]interface{}

Meta is used for additional page properties not in fedwiki spec

type Page

type Page struct {
	PageHeader `bson:",inline"`
	Story      Story   `json:"story,omitempty"`
	Journal    Journal `json:"journal,omitempty"`
}

Page represents a federated wiki page

func (*Page) Apply

func (page *Page) Apply(action Action) error

Apply modifies the page with an action

func (*Page) LastModified

func (page *Page) LastModified() time.Time

LastModified returns the date when the page was last modified if there is no such date it will return a zero time

type PageHeader struct {
	Slug     Slug   `json:"slug" bson:"_id"`
	Title    string `json:"title"`
	Date     Date   `json:"date"`
	Synopsis string `json:"synopsis,omitempty"`

	// may contain extra information specific to client/server
	Meta Meta `json:"meta,omitempty"`
}

PageHeader represents minimal useful information about the page

type PageStore

type PageStore interface {
	// Exists checks whether a page with `slug` exists
	Exists(slug Slug) bool
	// Create adds a new `page` with `slug`
	Create(slug Slug, page *Page) error
	// Load loads the page with identified by `slug`
	Load(slug Slug) (*Page, error)
	// Save saves the new page to `slug`
	Save(slug Slug, page *Page) error
	// List lists all the page headers
	List() ([]*PageHeader, error)
}

type Server

type Server struct {
	Handler  Handler
	Template Template
}

This implements basic management of request of headers and canonicalizes the requests

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type Slug

type Slug string

Slug is a string where Slugify(string(slug)) == slug

func Slugify

func Slugify(s string) Slug

Slugify converts text to a slug

  • numbers and '/' are left intact
  • letters will be lowercased (if possible)
  • '-', ',', '.', ' ', '_' will be converted to '-'
  • other symbols or punctuations will be converted to html entity reference name (if there exists such reference name)
  • everything else will be converted to '-'

Example:

"&Hello_世界/+!" ==> "amp-hello-世界/plus-excl"
"Hello  World  /  Test" ==> "hello-world/test"

type Story

type Story []Item

Story is the viewable content of the page

func (*Story) Append

func (s *Story) Append(item Item)

Appends adds the `item` as the last item in story

func (Story) IndexOf

func (s Story) IndexOf(id string) (index int, ok bool)

IndexOf returns the index of an item with `id` ok = false, if that item doesn't exist

func (*Story) InsertAfter

func (s *Story) InsertAfter(id string, item Item) error

InsertAfter adds the `item` after the item with `id`

func (*Story) Move

func (ps *Story) Move(id string, afterId string) error

Move moves the item with `id` after the item with `afterId`

func (*Story) Prepend

func (s *Story) Prepend(item Item)

Prepend adds the `item` as the first item in story

func (*Story) RemoveByID

func (s *Story) RemoveByID(id string) (item Item, err error)

Removes item with `id`

func (Story) SetByID

func (s Story) SetByID(id string, item Item) error

SetByID replaces item with `id` with `item`

type Template

type Template interface {
	// RenderHTML renders data as HTML with the appropriate template
	// template = "" means that it should be rendered as a regular page
	RenderHTML(w io.Writer, template string, data interface{}) error
}

Template is the interface that is used to render pages as HTML

Directories

Path Synopsis
cmd
example-time command
This is an example service for fedwiki
This is an example service for fedwiki
fedwiki command
internal
runetable command
This package implements common federated wiki types
This package implements common federated wiki types
pagestore contains default handler for a fedwiki.PageStore
pagestore contains default handler for a fedwiki.PageStore
folderstore
This package implements PageStore for a folder
This package implements PageStore for a folder
globstore
This package implements PageStore over a glob
This package implements PageStore over a glob
mongostore
This package implements PageStore for MongoDB
This package implements PageStore for MongoDB
multistore
This package implements dispatching PageStore
This package implements dispatching PageStore
This package implements federated wiki Plugin handling
This package implements federated wiki Plugin handling
This package implements sitemap and slugs Handler for a PageStore
This package implements sitemap and slugs Handler for a PageStore
This package implements simple HTML rendering for federated wiki
This package implements simple HTML rendering for federated wiki

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL