Skip to content
Snippets Groups Projects
Commit 96be5040 authored by Tom Preston-Werner's avatar Tom Preston-Werner
Browse files

Merge branch 'frontend'

parents e2403bf4 baaa7c6b
No related branches found
No related tags found
No related merge requests found
Showing
with 1114 additions and 30 deletions
Loading
Loading
@@ -30,6 +30,7 @@ formats and allowed extensions is:
* Textile: .textile
* RDoc: .rdoc
* Org Mode: .org
* Creole: .creole
* ReStructured Text: .rest.txt, .rst.txt, .rest, .rst
* ASCIIDoc: .asciidoc
* POD: .pod
Loading
Loading
@@ -69,10 +70,10 @@ or JavaScript. These tags will be stripped from the converted HTML.
 
To link to another Gollum wiki page, use the Gollum Page Link Tag.
 
[[Frodo]]
[[Frodo Baggins]]
 
The above tag will create a link to the corresponding page file named
`Frodo.ext` where `ext` may be any of the allowed extension types. The
`Frodo-Baggins.ext` where `ext` may be any of the allowed extension types. The
conversion is as follows:
 
1. Replace any spaces (U+0020) with dashes (U+002D)
Loading
Loading
@@ -230,6 +231,10 @@ Initialize the Gollum::Repo object:
wiki = Gollum::Wiki.new("my-gollum-repo.git")
# => <Gollum::Wiki>
 
By default, internal wiki links are all absolute from the root. To specify a different base path, you can send specify the `:base_path` option:
wiki = Gollum::Wiki.new("my-gollum-repo.git", :base_path => "/wiki")
Get the latest version of the given human or canonical page name:
 
page = wiki.page('page-name')
Loading
Loading
Loading
Loading
@@ -24,7 +24,11 @@ Gem::Specification.new do |s|
s.extra_rdoc_files = %w[README.md LICENSE]
 
s.add_dependency('grit', [">= 2.0.0", "< 3.0.0"])
s.add_dependency('github-markup', [">= 0.4.0", "< 1.0.0"])
s.add_dependency('albino', "~> 1.0.0")
s.add_dependency('sinatra', "~> 1.0.0")
s.add_dependency('mustache', [">= 0.11.2", "< 1.0.0"])
s.add_dependency('sanitize', "~> 1.0.0")
 
s.add_development_dependency('shoulda')
s.add_development_dependency('mocha')
Loading
Loading
# external
require 'grit'
require 'github/markup'
require 'sanitize'
 
# internal
require 'gollum/pagination'
Loading
Loading
@@ -12,4 +13,43 @@ require 'gollum/albino'
 
module Gollum
VERSION = '0.0.1'
end
\ No newline at end of file
SANITIZATION_OPTIONS = {
:elements => [
'a', 'abbr', 'acronym', 'address', 'area', 'b', 'big',
'blockquote', 'br', 'button', 'caption', 'center', 'cite',
'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir',
'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'form', 'h1',
'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input',
'ins', 'kbd', 'label', 'legend', 'li', 'map', 'menu',
'ol', 'optgroup', 'option', 'p', 'pre', 'q', 's', 'samp',
'select', 'small', 'span', 'strike', 'strong', 'sub',
'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th',
'thead', 'tr', 'tt', 'u', 'ul', 'var'
],
:attributes => {
:all => ['abbr', 'accept', 'accept-charset',
'accesskey', 'action', 'align', 'alt', 'axis',
'border', 'cellpadding', 'cellspacing', 'char',
'charoff', 'charset', 'checked', 'cite',
'class', 'clear', 'cols', 'colspan', 'color',
'compact', 'coords', 'datetime', 'dir',
'disabled', 'enctype', 'for', 'frame',
'headers', 'height', 'href', 'hreflang',
'hspace', 'id', 'ismap', 'label', 'lang',
'longdesc', 'maxlength', 'media', 'method',
'multiple', 'name', 'nohref', 'noshade',
'nowrap', 'prompt', 'readonly', 'rel', 'rev',
'rows', 'rowspan', 'rules', 'scope',
'selected', 'shape', 'size', 'span', 'src',
'start', 'summary', 'tabindex', 'target',
'title', 'type', 'usemap', 'valign', 'value',
'vspace', 'width']
},
:protocols => {
'a' => {'href' => ['http', 'https', 'mailto', :relative]},
'img' => {'href' => ['http', 'https', :relative]}
}
}
end
require 'rubygems'
require 'sinatra'
require 'gollum'
require 'mustache/sinatra'
require 'gollum/frontend/views/layout'
$path = "~/dev/sandbox/lotr2"
module Precious
class App < Sinatra::Base
register Mustache::Sinatra
dir = File.dirname(File.expand_path(__FILE__))
# We want to serve public assets for now
set :public, "#{dir}/public"
set :static, true
set :mustache, {
# Tell mustache where the Views constant lives
:namespace => Precious,
# Mustache templates live here
:templates => "#{dir}/templates",
# Tell mustache where the views are
:views => "#{dir}/views"
}
# Sinatra error handling
configure :development, :staging do
set :raise_errors, false
set :show_exceptions, true
set :dump_errors, true
set :clean_trace, false
end
get '/' do
show_page_or_file('Home')
end
get '/edit/:name' do
@name = params[:name]
wiki = Gollum::Wiki.new($path)
if page = wiki.page(@name)
@content = page.raw_data
mustache :edit
else
mustache :create
end
end
post '/edit/:name' do
name = params[:name]
wiki = Gollum::Wiki.new($path)
page = wiki.page(name)
commit = { :message => 'commit message',
:name => 'Tom Preston-Werner',
:email => 'tom@github.com' }
wiki.update_page(page, params[:content], commit)
redirect "/#{name}"
end
post '/create/:page' do
page = params[:page]
wiki = Gollum::Wiki.new($path)
commit = { :message => 'commit message',
:name => 'Tom Preston-Werner',
:email => 'tom@github.com' }
wiki.write_page(page, :markdown, params[:content], commit)
redirect "/#{page}"
end
get %r{/(.+?)/([0-9a-f]{40})} do
name = params[:captures][0]
wiki = Gollum::Wiki.new($path)
if page = wiki.page(name, params[:captures][1])
@page = page
@name = name
@content = page.formatted_data
mustache :page
else
halt 404
end
end
get '/*' do
show_page_or_file(params[:splat].first)
end
def show_page_or_file(name)
wiki = Gollum::Wiki.new($path)
if page = wiki.page(name)
@page = page
@name = name
@content = page.formatted_data
mustache :page
elsif file = wiki.file(name)
file.raw_data
else
@name = name
mustache :create
end
end
end
end
Precious::App.run!
h1, h2, h3, h4, h5, h6 {
color: #f90;
font-weight: bold;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
h1 {
font-size: 36pt;
}
h2 {
font-size: 32pt;
}
h3 {
font-size: 28pt;
}
h4 {
font-size: 24pt;
}
h5 {
font-size: 20pt;
}
h6 {
font-size: 16pt;
}
p {
font-family: Georgia, serif;
font-size: 14pt;
line-height: 22pt;
}
.highlight {
border: 1px solid #eee;
padding: 0;
margin: 0;
font-size: 12pt;
}
.highlight pre {
background-color: #f8f8ff;
margin: 0;
padding: .5em;
}
#nav {
width: 60em;
margin: 0 auto;
color: #666;
}
#content {
width: 60em;
margin: 0 auto;
color: #666;
}
a.absent {
color: #a00;
}
/* Forms */
textarea {
width: 100%;
height: 20em;
}
/* Images */
.frame {
margin: 1em 0;
display: inline-block;
}
.frame img {
display: block;
}
.frame > span {
display: block;
border: 1px solid #aaa;
padding: 4px;
}
.frame span span {
display: block;
font-size: 10pt;
margin: 0;
padding: 4px 0 2px 0;
text-align: center;
line-height: 10pt;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.float-left {
float: left;
padding: .5em 1em .25em 0;
}
.float-right {
float: right;
padding: .5em 0 .25em 1em;
}
.align-left {
display: block;
text-align: left;
}
.align-center {
display: block;
text-align: center;
}
.align-right {
display: block;
text-align: right;
}
\ No newline at end of file
a.absent {
color: #a00;
}
/* Images */
.frame {
margin: 0;
display: inline-block;
}
.frame img {
display: block;
}
.frame > span {
display: block;
border: 1px solid #aaa;
padding: 4px;
}
.frame span span {
display: block;
font-size: 10pt;
margin: 0;
padding: 4px 0 2px 0;
text-align: center;
line-height: 10pt;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.float-left {
float: left;
padding: .5em 1em .25em 0;
}
.float-right {
float: right;
padding: .5em 0 .25em 1em;
}
.align-left {
display: block;
text-align: left;
}
.align-center {
display: block;
text-align: center;
}
.align-right {
display: block;
text-align: right;
}
\ No newline at end of file
/****************************************************************************/
/* Base
/****************************************************************************/
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
color: black;
}
body {
background-color: white;
font: 13.34px helvetica, arial, freesans, clean, sans-serif;
*font-size: small;
}
table {
font-size: inherit;
font: 100%;
}
select, input[type=text], input[type=password], input[type=image], textarea {
font: 99% helvetica, arial, freesans, sans-serif;
}
select, option {
padding: 0 .25em;
}
optgroup {
margin-top: .5em;
}
input.text {
padding: 1px 0;
}
pre, code {
font: 12px Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
}
body * {
line-height: 1.4em;
}
p{ margin:1em 0; }
img {
border: 0;
}
abbr {
border-bottom: none;
}
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
* html .clearfix {height: 1%;}
.clearfix {display:inline-block;}
.clearfix {display: block;}
/* always show vertical scroll bar to prevent page jitter */
html {overflow-y: scroll;}
.site {
margin: 2em auto 0 auto;
width: 920px;
padding: 0 15px;
}
/****************************************************************************/
/* Guides
/****************************************************************************/
#guides {
}
/* index */
#guides .index {
}
#guides h1 {
margin-bottom: .5em;
}
#guides .index ul {
list-style-type: none;
font-size: 120%;
}
#guides .index ul li {
padding-left: 1.5em;
background: white url(/images/modules/guides/book.png) no-repeat;
}
#guides .index .new {
margin-top: 1em;
border-top: 1px solid #ccc;
padding-top: .5em;
}
#guides .index .new ul li {
background: white url(/images/modules/guides/book_add.png) no-repeat;
}
#guides .index .new ul li a {
color: #c00;
}
#guides .write .delete_page {
float: right;
}
/* guide */
#guides .guide {
overflow: hidden;
}
/* main */
#guides .guide .main {
float: left;
width: 50em;
}
/* sidebar */
#guides .guide .sidebar {
float: right;
width: 15em;
border-left: 4px solid #e6e6e6;
margin: 2.1em 0 0 0;
padding-left: 1em;
}
#guides .guide .sidebar h3 {
margin: 0 0 .5em 0;
}
#guides .guide .sidebar ul {
list-style-type: none;
margin: 0;
color: #888;
}
#guides .guide .sidebar ul li {
padding-left: 12px;
background: white url(/images/modules/guides/sidebar/bullet_blue.png) -4px 0 no-repeat;
margin: .2em 0;
}
/* admin */
#guides .admin {
clear: both;
margin-top: 3em;
border-top: 4px solid #e6e6e6;
padding-top: .3em;
overflow: hidden;
}
/* write */
#guides .write {
}
#guides .write label {
font-size: 110%;
color: #666;
display: block;
margin: 1em 0;
}
#guides .write input.text,
#guides .write textarea {
padding: 5px;
border: 1px solid #888;
}
#guides .write input.text {
width: 40em;
}
#guides .write textarea {
width: 100%;
height: 25em;
}
#guides .write label span.title {
color: black;
font-weight: bold;
}
#guides .write .actions input {
margin-right: 1em;
}
/****************************************************************************/
/* Wiki
/****************************************************************************/
.wikistyle h1, .wikistyle h2, .wikistyle h3, .wikistyle h4, .wikistyle h5, .wikistyle h6 {
border: 0 !important;
}
.wikistyle h1 {
font-size: 170% !important;
border-top: 4px solid #aaa !important;
padding-top: .5em !important;
margin-top: 1.5em !important;
}
.wikistyle h1:first-child {
margin-top: 0 !important;
padding-top: .25em !important;
border-top: none !important;
}
.wikistyle h2 {
font-size: 150% !important;
margin-top: 1.5em !important;
border-top: 4px solid #e0e0e0 !important;
padding-top: .5em !important;
}
.wikistyle h3 {
margin-top: 1em !important;
}
.wikistyle p {
margin: 1em 0 !important;
line-height: 1.5em !important;
}
.wikistyle ul {
margin: 1em 0 1em 2em !important;
}
.wikistyle ol {
margin: 1em 0 1em 2em !important;
}
.wikistyle ul ul,
.wikistyle ul ol,
.wikistyle ol ol,
.wikistyle ol ul {
margin-top: 0 !important;
margin-bottom: 0 !important;
}
.wikistyle blockquote {
margin: 1em 0 !important;
border-left: 5px solid #ddd !important;
padding-left: .6em !important;
color: #555 !important;
}
.wikistyle dt {
font-weight: bold !important;
margin-left: 1em !important;
}
.wikistyle dd {
margin-left: 2em !important;
margin-bottom: 1em !important;
}
.wikistyle table {
margin: 1em 0 !important;
}
.wikistyle table th {
border-bottom: 1px solid #bbb !important;
padding: .2em 1em !important;
}
.wikistyle table td {
border-bottom: 1px solid #ddd !important;
padding: .2em 1em !important;
}
.wikistyle pre {
margin: 1em 0 !important;
font-size: 90% !important;
background-color: #f8f8ff !important;
border: 1px solid #dedede !important;
padding: .5em !important;
line-height: 1.5em !important;
color: #444 !important;
overflow: auto !important;
}
.wikistyle pre code {
padding: 0 !important;
font-size: 100% !important;
background-color: #f8f8ff !important;
border: none !important;
}
.wikistyle code {
font-size: 90% !important;
background-color: #f8f8ff !important;
color: #444 !important;
padding: 0 .2em !important;
border: 1px solid #dedede !important;
}
/* console */
.wikistyle pre.console {
margin: 1em 0 !important;
font-size: 90% !important;
background-color: black !important;
padding: .5em !important;
line-height: 1.5em !important;
color: white !important;
}
.wikistyle pre.console code {
padding: 0 !important;
font-size: 100% !important;
background-color: black !important;
border: none !important;
color: white !important;
}
.wikistyle pre.console span {
color: #888 !important;
}
.wikistyle pre.console span.command {
color: yellow !important;
}
\ No newline at end of file
.highlight { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #999999 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #aaaaaa } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { font-weight: bold } /* Keyword.Constant */
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #009999 } /* Literal.Number */
.highlight .s { color: #d14 } /* Literal.String */
.highlight .na { color: #008080 } /* Name.Attribute */
.highlight .nb { color: #0086B3 } /* Name.Builtin */
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
.highlight .no { color: #008080 } /* Name.Constant */
.highlight .ni { color: #800080 } /* Name.Entity */
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
.highlight .nn { color: #555555 } /* Name.Namespace */
.highlight .nt { color: #000080 } /* Name.Tag */
.highlight .nv { color: #008080 } /* Name.Variable */
.highlight .ow { font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #009999 } /* Literal.Number.Float */
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
.highlight .sc { color: #d14 } /* Literal.String.Char */
.highlight .sd { color: #d14 } /* Literal.String.Doc */
.highlight .s2 { color: #d14 } /* Literal.String.Double */
.highlight .se { color: #d14 } /* Literal.String.Escape */
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
.highlight .si { color: #d14 } /* Literal.String.Interpol */
.highlight .sx { color: #d14 } /* Literal.String.Other */
.highlight .sr { color: #009926 } /* Literal.String.Regex */
.highlight .s1 { color: #d14 } /* Literal.String.Single */
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #008080 } /* Name.Variable.Class */
.highlight .vg { color: #008080 } /* Name.Variable.Global */
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
This diff is collapsed.
<div class="write">
<a href="/">&laquo; Home</a>
<h1>Create a new page</h1>
<form class="new_wiki" method="post" action="/create/{{name}}">
<label>
Title<br />
<input class="text" type="text" name="page" value="{{name}}" />
</label>
<label>
Body
<textarea name="content"></textarea>
</label>
<div class="actions">
<input type="submit" value="Create page" />
</div>
</form>
</div>
\ No newline at end of file
<div class="write">
<a href="/{{name}}">&laquo; Back</a>
<h1>Editing &ldquo;{{name}}&rdquo;</h1>
<form class="edit_wiki" method="post" action="/edit/{{name}}">
<label>
Body
<textarea name="content">{{content}}</textarea>
</label>
<div class="actions">
<input type="submit" value="Save page" />
</div>
</form>
</div>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Gollum - {{title}}</title>
<link rel="stylesheet" href="/css/screen.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/css/gollum.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/css/syntax.css" type="text/css" charset="utf-8" />
<script src="/javascript/jquery-1.4.2.min.js" type="text/javascript" />
</head>
<body>
<div id="main">
<div class="site">
<div id="guides">
{{{yield}}}
</div>
</div>
</div>
</body>
</html>
<div class="guide">
<div class="main">
<div class="actions">
<a href="/">Home</a> | <a href="/edit/{{name}}">Edit</a>
</div>
<h1>{{human_name}}</h1>
<div class="wikistyle">
{{{content}}}
</div>
</div>
</div>
<div class="admin">
<div style="float: left;">
<small>Last edited by <b>{{author}}</b>, {{date}}</small>
<div class="actions">
<a href="/">Home</a> | <a href="/edit/{{name}}">Edit</a>
</div>
</div>
<div style="float: right;">
<small>Versions:</small>
<select id="versions_select" name="versions_select">
{{#versions}}
<option {{#selected}}selected="true" {{/selected}}value="/{{name}}/{{id}}">Version {{num}} ({{id7}}) by {{author}}</option>
{{/versions}}
</select>
</div>
</div>
<script type="text/javascript">
$('#versions_select').change(function() {
location.href = this.value
})
</script>
\ No newline at end of file
module Precious
module Views
class Create < Layout
attr_reader :page
def title
"Create a new page"
end
end
end
end
module Precious
module Views
class Edit < Layout
attr_reader :page, :content
def title
"Edit"
end
end
end
end
module Precious
module Views
class Layout < Mustache
include Rack::Utils
alias_method :h, :escape_html
attr_reader :name
def title
"Home"
end
end
end
end
module Precious
module Views
class Page < Layout
attr_reader :content, :page
def human_name
@name.gsub(/-/, ' ')
end
def title
"A Page"
end
def author
@page.version.author.name
end
def date
@page.version.authored_date.strftime("%Y-%m-%d %H:%M:%S")
end
def versions
i = @page.versions.size + 1
@page.versions.map do |v|
i -= 1
{ :id => v.id,
:id7 => v.id[0..6],
:num => i,
:selected => @page.version.id == v.id,
:author => v.author.name }
end
end
end
end
end
Loading
Loading
@@ -22,11 +22,14 @@ module Gollum
#
# Returns the formatted String content.
def render
data = extract_tags(@data)
data = extract_code(data)
data = extract_code(@data)
data = extract_tags(data)
data = GitHub::Markup.render(@name, data) rescue ''
data = process_tags(data)
data = process_code(data)
data = Sanitize.clean(data, SANITIZATION_OPTIONS)
data = data.gsub(/<p><\/p>/, '')
data
end
 
#########################################################################
Loading
Loading
@@ -41,10 +44,16 @@ module Gollum
#
# Returns the placeholder'd String data.
def extract_tags(data)
data.gsub(/\[\[(.+?)\]\]/) do
id = Digest::SHA1.hexdigest($1)
@tagmap[id] = $1
id
data.gsub(/(.?)\[\[(.+?)\]\](.?)/m) do
if $1 == "'" && $3 != "'"
"[[#{$2}]]#{$3}"
elsif $2.include?('][')
$&
else
id = Digest::SHA1.hexdigest($2)
@tagmap[id] = $2
"#{$1}#{id}#{$3}"
end
end
end
 
Loading
Loading
@@ -85,22 +94,28 @@ module Gollum
def process_image_tag(tag)
parts = tag.split('|')
name = parts[0].strip
path = nil
 
if file = find_file(name)
path = "/#{file.path}"
elsif name =~ /^https?:\/\/.+(jpg|png|gif|svg|bmp)$/
path = name
end
if path
opts = parse_image_tag_options(tag)
 
containered = false
 
classes = [] # applied to whatever the outermost container is
attrs = [] # applied to the image
styles = [] # applied to the image
 
align = opts['align']
if opts['float']
containered = true
align ||= 'left'
if %w{left right}.include?(align)
classes << "float-#{align};"
classes << "float-#{align}"
end
elsif %w{top texttop middle absmiddle bottom absbottom baseline}.include?(align)
attrs << %{align="#{align}"}
Loading
Loading
@@ -113,13 +128,13 @@ module Gollum
 
if width = opts['width']
if width =~ /^\d+(\.\d+)?(em|px)$/
styles << "max-width: #{width};"
attrs << %{width="#{width}"}
end
end
 
if height = opts['height']
if height =~ /^\d+(\.\d+)?(em|px)$/
styles << "max-height: #{height};"
attrs << %{height="#{height}"}
end
end
 
Loading
Loading
@@ -129,21 +144,16 @@ module Gollum
 
attr_string = attrs.size > 0 ? attrs.join(' ') + ' ' : ''
 
style_string = ''
unless styles.empty?
style_string = %{ style="#{styles.join(' ')}"}
end
if opts['frame'] || containered
classes << 'frame' if opts['frame']
%{<div class="#{classes.join(' ')}">} +
%{<div>} +
%{<img src="/#{file.path}"#{style_string} #{attr_string}/>} +
(alt ? %{<p>#{alt}</p>} : '') +
%{</div>} +
%{</div>}
%{<span class="#{classes.join(' ')}">} +
%{<span>} +
%{<img src="/#{file.path}" #{attr_string}/>} +
(alt ? %{<span>#{alt}</span>} : '') +
%{</span>} +
%{</span>}
else
%{<img src="/#{file.path}"#{style_string} #{attr_string}/>}
%{<img src="#{path}" #{attr_string}/>}
end
end
end
Loading
Loading
@@ -192,7 +202,9 @@ module Gollum
parts = tag.split('|')
name = parts[0].strip
cname = Page.cname((parts[1] || parts[0]).strip)
%{<a href="#{cname}">#{name}</a>}
link = ::File.join(@wiki.base_path, cname)
presence = @wiki.page(cname) ? "present" : "absent"
%{<a class="internal #{presence}" href="#{link}">#{name}</a>}
end
 
# Find the given file in the repo.
Loading
Loading
@@ -221,7 +233,7 @@ module Gollum
#
# Returns the placeholder'd String data.
def extract_code(data)
data.gsub(/^``` ?(.+)\n(.+)\n```$/m) do
data.gsub(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
id = Digest::SHA1.hexdigest($2)
@codemap[id] = { :lang => $1, :code => $2 }
id
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ module Gollum
 
Wiki.page_class = self
 
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|re?st(\.txt)?|asciidoc|pod|\d)$/i
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|creole|re?st(\.txt)?|asciidoc|pod|\d)$/i
 
# Public: Initialize a page.
#
Loading
Loading
@@ -57,6 +57,8 @@ module Gollum
:rdoc
when /\.(org)$/i
:org
when /\.(creole)$/i
:creole
when /\.(re?st(\.txt)?)$/i
:rest
when /\.(asciidoc)$/i
Loading
Loading
@@ -117,6 +119,7 @@ module Gollum
when :textile then 'textile'
when :rdoc then 'rdoc'
when :org then 'org'
when :creole then 'creole'
when :rest then 'rest'
when :asciidoc then 'asciidoc'
when :pod then 'pod'
Loading
Loading
Loading
Loading
@@ -33,6 +33,11 @@ module Gollum
end
 
# The String base path to prefix to internal links. For example, when set
# to "/wiki", the page "Hobbit" will be linked as "/wiki/Hobbit". Defaults
# to "/".
attr_reader :base_path
# Public: Initialize a new Gollum Repo.
#
# repo - The String path to the Git repository that holds the Gollum
Loading
Loading
@@ -45,6 +50,7 @@ module Gollum
def initialize(path, options = {})
@path = path
@repo = Grit::Repo.new(path)
@base_path = options[:base_path] || "/"
@page_class = options[:page_class] || self.class.page_class
@file_class = options[:file_class] || self.class.file_class
end
Loading
Loading
@@ -94,7 +100,7 @@ module Gollum
if pcommit = @repo.commit('master')
map = tree_map(pcommit.tree)
end
map[path] = data
map[path] = normalize(data)
index = tree_map_to_index(map)
 
parents = pcommit ? [pcommit] : []
Loading
Loading
@@ -117,7 +123,7 @@ module Gollum
pcommit = @repo.commit('master')
map = tree_map(pcommit.tree)
index = tree_map_to_index(map)
index.add(page.path, data)
index.add(page.path, normalize(data))
 
actor = Grit::Actor.new(commit[:name], commit[:email])
index.commit(commit[:message], [pcommit], actor)
Loading
Loading
@@ -187,6 +193,15 @@ module Gollum
# Returns the String path.
attr_reader :path
 
# Normalize the data.
#
# data - The String data to be normalized.
#
# Returns the normalized data String.
def normalize(data)
data.gsub(/\r/, '')
end
# Fill an array with a list of pages.
#
# tree - The Grit::Tree to start with.
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment