Namespace (#1328)
* CSS to SCSS * Use sprockets * Use Sprockets helpers * Fix gollum.editor.js error when changing language * Add keybinding files required by ace and some ace ext files that are required or might be useful. * Move app paths to /gollum namespace, add route helpers for view templates * Use path helper for links in page view * Use path helper methods in javascript assets * Refactored sprockets helpers for mustache * Remove debugging
This commit is contained in:
+341
-336
@@ -1,6 +1,7 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require 'cgi'
|
||||
require 'sinatra'
|
||||
require 'sinatra/namespace'
|
||||
require 'gollum-lib'
|
||||
require 'mustache/sinatra'
|
||||
require 'stringex'
|
||||
@@ -47,11 +48,12 @@ end
|
||||
# }
|
||||
#
|
||||
# See the wiki.rb file for more details on wiki options
|
||||
|
||||
module Precious
|
||||
class App < Sinatra::Base
|
||||
register Mustache::Sinatra
|
||||
register Sinatra::Namespace
|
||||
include Precious::Helpers
|
||||
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
|
||||
set :sprockets, ::Precious::Assets.sprockets(dir)
|
||||
@@ -97,6 +99,7 @@ module Precious
|
||||
|
||||
Sprockets::Helpers.configure do |config|
|
||||
config.environment = settings.sprockets
|
||||
config.environment.context_class.class_variable_set(:@@base_url, @base_url)
|
||||
config.prefix = "#{@base_url}/#{Precious::Assets::ASSET_URL}"
|
||||
config.digest = @use_static_assets
|
||||
if @use_static_assets
|
||||
@@ -110,344 +113,372 @@ module Precious
|
||||
redirect clean_url(::File.join(@base_url, @page_dir, wiki_new.index_page))
|
||||
end
|
||||
|
||||
get '/assets/*' do
|
||||
env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '')
|
||||
if @use_static_assets
|
||||
env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url
|
||||
not_found_msg = "Not found."
|
||||
not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]}
|
||||
Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env)
|
||||
else
|
||||
settings.sprockets.call(env)
|
||||
end
|
||||
end
|
||||
namespace '/gollum' do
|
||||
|
||||
get '/last-commit-info' do
|
||||
content_type :json
|
||||
if page = wiki_page(params[:path]).page
|
||||
version = page.last_version
|
||||
{:author => version.author.name, :date => version.authored_date}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
get '/emoji/:name' do
|
||||
begin
|
||||
[200, {'Content-Type' => 'image/png'}, emoji(params['name'])]
|
||||
rescue ArgumentError
|
||||
not_found
|
||||
end
|
||||
end
|
||||
|
||||
get '/data/*' do
|
||||
if page = wiki_page(params[:splat].first).page
|
||||
page.raw_data
|
||||
end
|
||||
end
|
||||
|
||||
get %r{/(edit|create)/custom\.(js|css)} do
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
post %r{/(deleteFile|rename|edit|create)/custom\.(js|css)} do
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
post %r{/revert/custom\.(js|css)/.*/.*} do
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
get '/edit/*' do
|
||||
forbid unless @allow_editing
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@name = join_page_name(wikip.name, wikip.ext)
|
||||
@path = wikip.path
|
||||
@upload_dest = find_upload_dest(@path)
|
||||
|
||||
wiki = wikip.wiki
|
||||
@allow_uploads = wiki.allow_uploads
|
||||
if page = wikip.page
|
||||
@page = page
|
||||
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
||||
@content = page.text_data
|
||||
mustache :edit
|
||||
else
|
||||
redirect to("/create/#{encodeURIComponent(@name)}")
|
||||
end
|
||||
end
|
||||
|
||||
post '/uploadFile' do
|
||||
wiki = wiki_new
|
||||
|
||||
unless wiki.allow_uploads
|
||||
@message = "File uploads are disabled"
|
||||
mustache :error
|
||||
return
|
||||
get '/assets/*' do
|
||||
env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '')
|
||||
if @use_static_assets
|
||||
env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url
|
||||
not_found_msg = "Not found."
|
||||
not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]}
|
||||
Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env)
|
||||
else
|
||||
settings.sprockets.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
if params[:file]
|
||||
fullname = params[:file][:filename]
|
||||
tempfile = params[:file][:tempfile]
|
||||
end
|
||||
halt 500 unless tempfile.is_a? Tempfile
|
||||
|
||||
# Remove page file dir prefix from upload path if necessary -- committer handles this itself
|
||||
dir = wiki.per_page_uploads ? params[:upload_dest] : ::File.join([wiki.page_file_dir, 'uploads'].compact)
|
||||
ext = ::File.extname(fullname)
|
||||
format = ext.split('.').last || 'txt'
|
||||
filename = ::File.basename(fullname, ext)
|
||||
contents = ::File.read(tempfile)
|
||||
reponame = "#{filename}.#{format}"
|
||||
|
||||
head = wiki.repo.head
|
||||
|
||||
options = {
|
||||
:message => "Uploaded file to #{dir}/#{reponame}",
|
||||
:parent => wiki.repo.head.commit,
|
||||
}
|
||||
author = session['gollum.author']
|
||||
unless author.nil?
|
||||
options.merge! author
|
||||
get '/last-commit-info' do
|
||||
content_type :json
|
||||
if page = wiki_page(params[:path]).page
|
||||
version = page.last_version
|
||||
{:author => version.author.name, :date => version.authored_date}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
committer = Gollum::Committer.new(wiki, options)
|
||||
committer.add_to_index(dir, filename, format, contents)
|
||||
committer.after_commit do |committer, sha|
|
||||
wiki.clear_cache
|
||||
committer.update_working_dir(dir, filename, format)
|
||||
get '/emoji/:name' do
|
||||
begin
|
||||
[200, {'Content-Type' => 'image/png'}, emoji(params['name'])]
|
||||
rescue ArgumentError
|
||||
not_found
|
||||
end
|
||||
end
|
||||
|
||||
get '/data/*' do
|
||||
if page = wiki_page(params[:splat].first).page
|
||||
page.raw_data
|
||||
end
|
||||
end
|
||||
|
||||
get %r{/(edit|create)/custom\.(js|css)} do
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
post %r{/(deleteFile|rename|edit|create)/custom\.(js|css)} do
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
post %r{/revert/custom\.(js|css)/.*/.*} do
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
get '/edit/*' do
|
||||
forbid unless @allow_editing
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@name = join_page_name(wikip.name, wikip.ext)
|
||||
@path = wikip.path
|
||||
@upload_dest = find_upload_dest(@path)
|
||||
|
||||
wiki = wikip.wiki
|
||||
@allow_uploads = wiki.allow_uploads
|
||||
if page = wikip.page
|
||||
@page = page
|
||||
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
||||
@content = page.text_data
|
||||
mustache :edit
|
||||
else
|
||||
redirect_to("/create/#{encodeURIComponent(@name)}")
|
||||
end
|
||||
end
|
||||
|
||||
post '/uploadFile' do
|
||||
wiki = wiki_new
|
||||
|
||||
unless wiki.allow_uploads
|
||||
@message = "File uploads are disabled"
|
||||
mustache :error
|
||||
return
|
||||
end
|
||||
|
||||
if params[:file]
|
||||
fullname = params[:file][:filename]
|
||||
tempfile = params[:file][:tempfile]
|
||||
end
|
||||
halt 500 unless tempfile.is_a? Tempfile
|
||||
|
||||
# Remove page file dir prefix from upload path if necessary -- committer handles this itself
|
||||
dir = wiki.per_page_uploads ? params[:upload_dest] : ::File.join([wiki.page_file_dir, 'uploads'].compact)
|
||||
ext = ::File.extname(fullname)
|
||||
format = ext.split('.').last || 'txt'
|
||||
filename = ::File.basename(fullname, ext)
|
||||
contents = ::File.read(tempfile)
|
||||
reponame = "#{filename}.#{format}"
|
||||
|
||||
head = wiki.repo.head
|
||||
|
||||
options = {
|
||||
:message => "Uploaded file to #{dir}/#{reponame}",
|
||||
:parent => wiki.repo.head.commit,
|
||||
}
|
||||
author = session['gollum.author']
|
||||
unless author.nil?
|
||||
options.merge! author
|
||||
end
|
||||
|
||||
begin
|
||||
committer = Gollum::Committer.new(wiki, options)
|
||||
committer.add_to_index(dir, filename, format, contents)
|
||||
committer.after_commit do |committer, sha|
|
||||
wiki.clear_cache
|
||||
committer.update_working_dir(dir, filename, format)
|
||||
end
|
||||
committer.commit
|
||||
redirect to(request.referer)
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@message = "Duplicate page: #{e.message}"
|
||||
mustache :error
|
||||
end
|
||||
end
|
||||
|
||||
post '/deleteFile/*' do
|
||||
forbid unless @allow_editing
|
||||
wiki = wiki_new
|
||||
filepath = params[:splat].first
|
||||
unless filepath.nil?
|
||||
commit = commit_message
|
||||
commit[:message] = "Deleted #{filepath}"
|
||||
wiki.delete_file(filepath, commit)
|
||||
end
|
||||
|
||||
redirect_to('/pages')
|
||||
end
|
||||
|
||||
post '/rename/*' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
halt 500 if wikip.nil?
|
||||
wiki = wikip.wiki
|
||||
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||
rename = params[:rename]
|
||||
halt 500 if page.nil?
|
||||
halt 500 if rename.nil? or rename.empty?
|
||||
|
||||
# Fixup the rename if it is a relative path
|
||||
# In 1.8.7 rename[0] != rename[0..0]
|
||||
if rename[0..0] != '/'
|
||||
source_dir = ::File.dirname(page.path)
|
||||
source_dir = '' if source_dir == '.'
|
||||
(target_dir, target_name) = ::File.split(rename)
|
||||
target_dir = target_dir == '' ? source_dir : "#{source_dir}/#{target_dir}"
|
||||
rename = "#{target_dir}/#{target_name}"
|
||||
end
|
||||
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = { :committer => committer }
|
||||
|
||||
success = wiki.rename_page(page, rename, commit)
|
||||
if !success
|
||||
# This occurs on NOOPs, for example renaming A => A
|
||||
redirect to("/#{page.escaped_url_path}")
|
||||
return
|
||||
end
|
||||
committer.commit
|
||||
redirect to(request.referer)
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@message = "Duplicate page: #{e.message}"
|
||||
mustache :error
|
||||
end
|
||||
end
|
||||
|
||||
post '/deleteFile/*' do
|
||||
forbid unless @allow_editing
|
||||
wiki = wiki_new
|
||||
filepath = params[:splat].first
|
||||
unless filepath.nil?
|
||||
commit = commit_message
|
||||
commit[:message] = "Deleted #{filepath}"
|
||||
wiki.delete_file(filepath, commit)
|
||||
end
|
||||
|
||||
redirect to('/pages')
|
||||
end
|
||||
|
||||
post '/rename/*' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
halt 500 if wikip.nil?
|
||||
wiki = wikip.wiki
|
||||
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||
rename = params[:rename]
|
||||
halt 500 if page.nil?
|
||||
halt 500 if rename.nil? or rename.empty?
|
||||
|
||||
# Fixup the rename if it is a relative path
|
||||
# In 1.8.7 rename[0] != rename[0..0]
|
||||
if rename[0..0] != '/'
|
||||
source_dir = ::File.dirname(page.path)
|
||||
source_dir = '' if source_dir == '.'
|
||||
(target_dir, target_name) = ::File.split(rename)
|
||||
target_dir = target_dir == '' ? source_dir : "#{source_dir}/#{target_dir}"
|
||||
rename = "#{target_dir}/#{target_name}"
|
||||
end
|
||||
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = { :committer => committer }
|
||||
|
||||
success = wiki.rename_page(page, rename, commit)
|
||||
if !success
|
||||
# This occurs on NOOPs, for example renaming A => A
|
||||
wikip = wiki_page(rename)
|
||||
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||
return if page.nil?
|
||||
redirect to("/#{page.escaped_url_path}")
|
||||
return
|
||||
end
|
||||
committer.commit
|
||||
|
||||
wikip = wiki_page(rename)
|
||||
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||
return if page.nil?
|
||||
redirect to("/#{page.escaped_url_path}")
|
||||
end
|
||||
|
||||
post '/edit/*' do
|
||||
path = "/#{clean_url(sanitize_empty_params(params[:path]))}"
|
||||
page_name = CGI.unescape(params[:page])
|
||||
wiki = wiki_new
|
||||
page = wiki.paged(page_name, path, exact = true)
|
||||
return if page.nil?
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = { :committer => committer }
|
||||
|
||||
update_wiki_page(wiki, page, params[:content], commit, page.name, params[:format])
|
||||
update_wiki_page(wiki, page.header, params[:header], commit) if params[:header]
|
||||
update_wiki_page(wiki, page.footer, params[:footer], commit) if params[:footer]
|
||||
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
|
||||
committer.commit
|
||||
|
||||
redirect to("/#{page.escaped_url_path}") unless page.nil?
|
||||
end
|
||||
|
||||
get '/delete/*' do
|
||||
forbid unless @allow_editing
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
name = join_page_name(wikip.name, wikip.ext)
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
unless page.nil?
|
||||
commit = commit_message
|
||||
commit[:message] = "Destroyed #{name} (#{page.format})"
|
||||
wiki.delete_page(page, commit)
|
||||
end
|
||||
|
||||
redirect to('/')
|
||||
end
|
||||
post '/edit/*' do
|
||||
path = "/#{clean_url(sanitize_empty_params(params[:path]))}"
|
||||
page_name = CGI.unescape(params[:page])
|
||||
wiki = wiki_new
|
||||
page = wiki.paged(page_name, path, exact = true)
|
||||
return if page.nil?
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = { :committer => committer }
|
||||
|
||||
get '/create/*' do
|
||||
forbid unless @allow_editing
|
||||
if settings.wiki_options[:template_page] then
|
||||
temppage = wiki_page("/_Template")
|
||||
@template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed."
|
||||
update_wiki_page(wiki, page, params[:content], commit, page.name, params[:format])
|
||||
update_wiki_page(wiki, page.header, params[:header], commit) if params[:header]
|
||||
update_wiki_page(wiki, page.footer, params[:footer], commit) if params[:footer]
|
||||
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
|
||||
committer.commit
|
||||
|
||||
redirect to("/#{page.escaped_url_path}") unless page.nil?
|
||||
end
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@name = wikip.name.to_url
|
||||
@ext = wikip.ext
|
||||
@path = wikip.path
|
||||
@allow_uploads = wikip.wiki.allow_uploads
|
||||
@upload_dest = find_upload_dest(@path)
|
||||
|
||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||
unless page_dir.empty?
|
||||
# --page-file-dir docs
|
||||
# /docs/Home should be created in /Home
|
||||
# not /docs/Home because write_page will append /docs
|
||||
@path = @path.sub(page_dir, '/') if @path.start_with? page_dir
|
||||
end
|
||||
@path = clean_path(@path)
|
||||
|
||||
page = wikip.page
|
||||
if page
|
||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||
redirect to("/#{clean_url(::File.join(page_dir, page.escaped_url_path))}")
|
||||
else
|
||||
unless Gollum::Page.format_for("#{@name}#{@ext}")
|
||||
@name = "#{@name}#{@ext}"
|
||||
@ext = nil
|
||||
get '/delete/*' do
|
||||
forbid unless @allow_editing
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
name = join_page_name(wikip.name, wikip.ext)
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
unless page.nil?
|
||||
commit = commit_message
|
||||
commit[:message] = "Destroyed #{name} (#{page.format})"
|
||||
wiki.delete_page(page, commit)
|
||||
end
|
||||
mustache :create
|
||||
|
||||
redirect to('/')
|
||||
end
|
||||
end
|
||||
|
||||
post '/create' do
|
||||
name = params[:page].to_url
|
||||
path = sanitize_empty_params(params[:path]) || ''
|
||||
format = params[:format].intern
|
||||
wiki = wiki_new
|
||||
|
||||
path.gsub!(/^\//, '')
|
||||
|
||||
begin
|
||||
wiki.write_page(name, format, params[:content], commit_message, path)
|
||||
get '/create/*' do
|
||||
forbid unless @allow_editing
|
||||
if settings.wiki_options[:template_page] then
|
||||
temppage = wiki_page("/_Template")
|
||||
@template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed."
|
||||
end
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@name = wikip.name.to_url
|
||||
@ext = wikip.ext
|
||||
@path = wikip.path
|
||||
@allow_uploads = wikip.wiki.allow_uploads
|
||||
@upload_dest = find_upload_dest(@path)
|
||||
|
||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||
redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}")
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@message = "Duplicate page: #{e.message}"
|
||||
mustache :error
|
||||
unless page_dir.empty?
|
||||
# --page-file-dir docs
|
||||
# /docs/Home should be created in /Home
|
||||
# not /docs/Home because write_page will append /docs
|
||||
@path = @path.sub(page_dir, '/') if @path.start_with? page_dir
|
||||
end
|
||||
@path = clean_path(@path)
|
||||
|
||||
page = wikip.page
|
||||
if page
|
||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||
redirect to("/#{clean_url(::File.join(page_dir, page.escaped_url_path))}")
|
||||
else
|
||||
unless Gollum::Page.format_for("#{@name}#{@ext}")
|
||||
@name = "#{@name}#{@ext}"
|
||||
@ext = nil
|
||||
end
|
||||
mustache :create
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
post '/revert/*/:sha1/:sha2' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@path = wikip.path
|
||||
@name = join_page_name(wikip.name, wikip.ext)
|
||||
wiki = wikip.wiki
|
||||
@page = wiki.paged(@name, @path)
|
||||
sha1 = params[:sha1]
|
||||
sha2 = params[:sha2]
|
||||
post '/create' do
|
||||
name = params[:page].to_url
|
||||
path = sanitize_empty_params(params[:path]) || ''
|
||||
format = params[:format].intern
|
||||
wiki = wiki_new
|
||||
|
||||
commit = commit_message
|
||||
commit[:message] = "Revert commit #{sha1.chars.take(7).join}"
|
||||
if wiki.revert_page(@page, sha1, sha2, commit)
|
||||
redirect to("/#{@page.escaped_url_path}")
|
||||
else
|
||||
sha2, sha1 = sha1, "#{sha1}^" if !sha2
|
||||
@versions = [sha1, sha2]
|
||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
@message = "The patch does not apply."
|
||||
path.gsub!(/^\//, '')
|
||||
|
||||
begin
|
||||
wiki.write_page(name, format, params[:content], commit_message, path)
|
||||
|
||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||
redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}")
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@message = "Duplicate page: #{e.message}"
|
||||
mustache :error
|
||||
end
|
||||
end
|
||||
|
||||
post '/revert/*/:sha1/:sha2' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@path = wikip.path
|
||||
@name = join_page_name(wikip.name, wikip.ext)
|
||||
wiki = wikip.wiki
|
||||
@page = wiki.paged(@name, @path)
|
||||
sha1 = params[:sha1]
|
||||
sha2 = params[:sha2]
|
||||
|
||||
commit = commit_message
|
||||
commit[:message] = "Revert commit #{sha1.chars.take(7).join}"
|
||||
if wiki.revert_page(@page, sha1, sha2, commit)
|
||||
redirect to("/#{@page.escaped_url_path}")
|
||||
else
|
||||
sha2, sha1 = sha1, "#{sha1}^" if !sha2
|
||||
@versions = [sha1, sha2]
|
||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
@message = "The patch does not apply."
|
||||
mustache :compare
|
||||
end
|
||||
end
|
||||
|
||||
post '/preview' do
|
||||
wiki = wiki_new
|
||||
@name = params[:page] || "Preview"
|
||||
@page = wiki.preview_page(@name, params[:content], params[:format])
|
||||
@content = @page.formatted_data
|
||||
@toc_content = wiki.universal_toc ? @page.toc_data : nil
|
||||
@mathjax = wiki.mathjax
|
||||
@h1_title = wiki.h1_title
|
||||
@editable = false
|
||||
@bar_side = wiki.bar_side
|
||||
@allow_uploads = wiki.allow_uploads
|
||||
mustache :page
|
||||
end
|
||||
|
||||
get '/history/*' do
|
||||
@page = wiki_page(params[:splat].first).page
|
||||
@page_num = [params[:page].to_i, 1].max
|
||||
unless @page.nil?
|
||||
@versions = @page.versions(:page => @page_num, :follow => settings.wiki_options.fetch(:follow_renames, ::Gollum::GIT_ADAPTER == 'rjgit' ? false : true))
|
||||
mustache :history
|
||||
else
|
||||
redirect to("/")
|
||||
end
|
||||
end
|
||||
|
||||
get '/latest_changes' do
|
||||
@wiki = wiki_new
|
||||
max_count = settings.wiki_options.fetch(:latest_changes_count, 10)
|
||||
@versions = @wiki.latest_changes({:max_count => max_count})
|
||||
mustache :latest_changes
|
||||
end
|
||||
|
||||
post '/compare/*' do
|
||||
@file = encodeURIComponent(params[:splat].first)
|
||||
@versions = params[:versions] || []
|
||||
if @versions.size < 2
|
||||
redirect_to("/history/#{@file}")
|
||||
else
|
||||
redirect_to("/compare/%s/%s...%s" % [
|
||||
@file,
|
||||
@versions.last,
|
||||
@versions.first]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
get %r{
|
||||
/compare/ # match any URL beginning with /compare/
|
||||
(.+) # extract the full path (including any directories)
|
||||
/ # match the final slash
|
||||
([^.]+) # match the first SHA1
|
||||
\.{2,3} # match .. or ...
|
||||
(.+) # match the second SHA1
|
||||
}x do |path, start_version, end_version|
|
||||
wikip = wiki_page(path)
|
||||
@path = wikip.path
|
||||
@name = join_page_name(wikip.name, wikip.ext)
|
||||
@versions = [start_version, end_version]
|
||||
wiki = wikip.wiki
|
||||
@page = wikip.page
|
||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
mustache :compare
|
||||
end
|
||||
end
|
||||
|
||||
post '/preview' do
|
||||
wiki = wiki_new
|
||||
@name = params[:page] || "Preview"
|
||||
@page = wiki.preview_page(@name, params[:content], params[:format])
|
||||
@content = @page.formatted_data
|
||||
@toc_content = wiki.universal_toc ? @page.toc_data : nil
|
||||
@mathjax = wiki.mathjax
|
||||
@h1_title = wiki.h1_title
|
||||
@editable = false
|
||||
@bar_side = wiki.bar_side
|
||||
@allow_uploads = wiki.allow_uploads
|
||||
mustache :page
|
||||
end
|
||||
|
||||
get '/history/*' do
|
||||
@page = wiki_page(params[:splat].first).page
|
||||
@page_num = [params[:page].to_i, 1].max
|
||||
unless @page.nil?
|
||||
@versions = @page.versions(:page => @page_num, :follow => settings.wiki_options.fetch(:follow_renames, ::Gollum::GIT_ADAPTER == 'rjgit' ? false : true))
|
||||
mustache :history
|
||||
else
|
||||
redirect to("/")
|
||||
get '/search' do
|
||||
@query = params[:q] || ''
|
||||
wiki = wiki_new
|
||||
# Sort wiki search results by count (desc) and then by name (asc)
|
||||
@results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse
|
||||
@name = @query
|
||||
mustache :search
|
||||
end
|
||||
end
|
||||
|
||||
get '/latest_changes' do
|
||||
@wiki = wiki_new
|
||||
max_count = settings.wiki_options.fetch(:latest_changes_count, 10)
|
||||
@versions = @wiki.latest_changes({:max_count => max_count})
|
||||
mustache :latest_changes
|
||||
end
|
||||
|
||||
post '/compare/*' do
|
||||
@file = encodeURIComponent(params[:splat].first)
|
||||
@versions = params[:versions] || []
|
||||
if @versions.size < 2
|
||||
redirect to("/history/#{@file}")
|
||||
else
|
||||
redirect to("/compare/%s/%s...%s" % [
|
||||
@file,
|
||||
@versions.last,
|
||||
@versions.first]
|
||||
)
|
||||
get %r{
|
||||
/pages # match any URL beginning with /pages
|
||||
(?: # begin an optional non-capturing group
|
||||
/(.+) # capture any path after the "/pages" excluding the leading slash
|
||||
)? # end the optional non-capturing group
|
||||
}x do |path|
|
||||
@path = extract_path(path) if path
|
||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||
@results = wiki.pages
|
||||
@results += wiki.files
|
||||
@results = @results.sort_by { |p| p.name.downcase } # Sort Results alphabetically, fixes 922
|
||||
@ref = wiki.ref
|
||||
mustache :pages
|
||||
end
|
||||
end
|
||||
|
||||
get %r{
|
||||
/compare/ # match any URL beginning with /compare/
|
||||
(.+) # extract the full path (including any directories)
|
||||
/ # match the final slash
|
||||
([^.]+) # match the first SHA1
|
||||
\.{2,3} # match .. or ...
|
||||
(.+) # match the second SHA1
|
||||
}x do |path, start_version, end_version|
|
||||
wikip = wiki_page(path)
|
||||
@path = wikip.path
|
||||
@name = join_page_name(wikip.name, wikip.ext)
|
||||
@versions = [start_version, end_version]
|
||||
wiki = wikip.wiki
|
||||
@page = wikip.page
|
||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
mustache :compare
|
||||
end
|
||||
|
||||
get %r{/(.+?)/([0-9a-f]{40})} do
|
||||
file_path = params[:captures][0]
|
||||
version = params[:captures][1]
|
||||
@@ -468,32 +499,6 @@ module Precious
|
||||
end
|
||||
end
|
||||
|
||||
get '/search' do
|
||||
@query = params[:q] || ''
|
||||
wiki = wiki_new
|
||||
# Sort wiki search results by count (desc) and then by name (asc)
|
||||
@results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse
|
||||
@name = @query
|
||||
mustache :search
|
||||
end
|
||||
|
||||
get %r{
|
||||
/pages # match any URL beginning with /pages
|
||||
(?: # begin an optional non-capturing group
|
||||
/(.+) # capture any path after the "/pages" excluding the leading slash
|
||||
)? # end the optional non-capturing group
|
||||
}x do |path|
|
||||
@path = extract_path(path) if path
|
||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||
@results = wiki.pages
|
||||
@results += wiki.files
|
||||
@results = @results.sort_by { |p| p.name.downcase } # Sort Results alphabetically, fixes 922
|
||||
@ref = wiki.ref
|
||||
mustache :pages
|
||||
end
|
||||
|
||||
|
||||
get '/*' do
|
||||
show_page_or_file(params[:splat].first)
|
||||
end
|
||||
@@ -525,7 +530,7 @@ module Precious
|
||||
else
|
||||
if @allow_editing
|
||||
page_path = [path, join_page_name(name, ext)].compact.join('/')
|
||||
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
|
||||
redirect to("/gollum/create/#{clean_url(encodeURIComponent(page_path))}")
|
||||
else
|
||||
@message = "The requested page does not exist."
|
||||
status 404
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module Precious
|
||||
module Assets
|
||||
MANIFEST = %w(app.js app.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)
|
||||
ASSET_URL = 'assets'
|
||||
ASSET_URL = 'gollum/assets'
|
||||
|
||||
def self.sprockets(dir = File.dirname(File.expand_path(__FILE__)))
|
||||
env = Sprockets::Environment.new
|
||||
@@ -12,6 +12,13 @@ module Precious
|
||||
|
||||
env.js_compressor = :uglify
|
||||
env.css_compressor = :scss
|
||||
|
||||
env.context_class.class_eval do
|
||||
def base_url
|
||||
self.class.class_variable_get(:@@base_url)
|
||||
end
|
||||
include ::Precious::Views::RouteHelpers
|
||||
end
|
||||
env
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,4 +28,4 @@
|
||||
//= require ace-1.3.1/ext-textarea.js
|
||||
//= require ace-1.3.1/ext-themelist.js
|
||||
//= require ace-1.3.1/ext-whitespace.js
|
||||
//= require jquery.resize
|
||||
//= require jquery.resize
|
||||
+1
-1
@@ -209,7 +209,7 @@
|
||||
formData.append('file', file);
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/uploadFile',
|
||||
url: '<%= upload_file_path %>',
|
||||
data: formData,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
+11
-7
@@ -47,7 +47,7 @@ $(document).ready(function() {
|
||||
$('#delete-link').click( function(e) {
|
||||
var ok = confirm($(this).data('confirm'));
|
||||
if ( ok ) {
|
||||
var loc = baseUrl + '/delete/' + pageFullPath;
|
||||
var loc = '<%= delete_path %>/' + pageFullPath;
|
||||
window.location = loc;
|
||||
}
|
||||
// Don't navigate on cancel.
|
||||
@@ -162,7 +162,7 @@ $(document).ready(function() {
|
||||
{
|
||||
type: 'file',
|
||||
context: 'Your uploaded file will be accessible at<br>/'+uploadDest+'/[filename]',
|
||||
action: baseUrl + '/uploadFile'
|
||||
action: '<%= upload_file_path %>'
|
||||
}
|
||||
],
|
||||
OK: function( res ) {
|
||||
@@ -226,10 +226,14 @@ $(document).ready(function() {
|
||||
// In the pages view, pageFullPath isn't defined.
|
||||
// The new button will still expect a value however.
|
||||
// So we try to figure one out from window.location
|
||||
path = baseUrl == '' ? window.location.pathname.substr(1)
|
||||
: window.location.pathname.substr(baseUrl.length + 1);
|
||||
path = window.location.pathname.substr(1)
|
||||
// Remove the page viewer part of the url.
|
||||
path = path.replace(/^pages\/?/,'')
|
||||
<%
|
||||
pages_path_uri = pages_path
|
||||
pages_path_uri = pages_path_uri[1..-1] if pages_path_uri[0] == '/'
|
||||
pages_path_uri = pages_path_uri.gsub('/','\/')
|
||||
%>
|
||||
path = path.replace(/^<%= pages_path_uri %>\/?/,'')
|
||||
// For consistency remove the trailing /
|
||||
path = path.replace(/\/$/,'')
|
||||
}
|
||||
@@ -260,7 +264,7 @@ $(document).ready(function() {
|
||||
for( var i=0; i < name_parts.length; i++ ){
|
||||
name_encoded.push(encodeURIComponent(name_parts[i]));
|
||||
}
|
||||
window.location = baseUrl + name_encoded.join('/');
|
||||
window.location = '<%= create_path %>' + name_encoded.join('/');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -315,7 +319,7 @@ $(document).ready(function() {
|
||||
if( $("#last-edit").length ) {
|
||||
$("#page-info-toggle").click ( function () {
|
||||
$.ajax({
|
||||
url: '/last-commit-info',
|
||||
url: '<%= last_commit_info_path %>',
|
||||
data: {path: $("#page-info-toggle").data('pagepath')},
|
||||
success: function ( data ) {
|
||||
$("#last-edit").html('Last edited by <b>' + data.author + '</b>, ' + data.date);
|
||||
@@ -325,7 +325,7 @@ a {
|
||||
|
||||
@include alt-box-model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* @control title */
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
{{#allow_editing}}
|
||||
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{edit_path}}/{{escaped_url_path}}"
|
||||
class="action-edit-page">Edit Page</a></li>
|
||||
{{/allow_editing}}
|
||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||
class="action-page-history">Page History</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -25,11 +25,11 @@
|
||||
|
||||
{{#show_revert}}
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||
class="action-page-history">Back to Page History</a></li>
|
||||
{{#allow_editing}}
|
||||
<li class="minibutton">
|
||||
<form name="gollum-revert" action="{{base_url}}/revert/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form">
|
||||
<form name="gollum-revert" action="{{revert_path}}/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form">
|
||||
<a href="#" class="gollum-revert-button">Revert Changes</a>
|
||||
</form>
|
||||
</li>
|
||||
@@ -53,7 +53,7 @@
|
||||
</div>
|
||||
<div id="footer">
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||
class="action-page-history">Back to Page History</a></li>
|
||||
{{#show_revert}}
|
||||
{{#allow_editing}}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||
class="action-page-history">Page History</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<div id="gollum-editor" data-escaped-name="{{escaped_name}}" class="{{#is_create_page}}create{{/is_create_page}}{{#is_edit_page}}edit{{/is_edit_page}} {{#allow_uploads}}uploads-allowed{{/allow_uploads}}">
|
||||
{{#is_create_page}}
|
||||
<form name="gollum-editor" action="{{base_url}}/create" method="post">
|
||||
<form name="gollum-editor" action="{{create_path}}" method="post">
|
||||
{{/is_create_page}}
|
||||
{{#is_edit_page}}
|
||||
<form name="gollum-editor" action="{{base_url}}/edit/{{escaped_name}}" method="post">
|
||||
<form name="gollum-editor" action="{{edit_path}}/{{escaped_name}}" method="post">
|
||||
{{/is_edit_page}}
|
||||
<fieldset id="gollum-editor-fields">
|
||||
{{#is_create_page}}
|
||||
@@ -147,7 +147,7 @@
|
||||
<span class="jaws"><br></span>
|
||||
<input type="submit" id="gollum-editor-submit" value="Save" title="Save current changes">
|
||||
<a href="" id="gollum-editor-cancel" class="minibutton" title="Cancel editing" onClick="window.history.back()">Cancel</a>
|
||||
<a href="{{base_url}}/preview" id="gollum-editor-preview" class="minibutton" title="Preview this Page">Preview</a>
|
||||
<a href="{{preview_path}}" id="gollum-editor-preview" class="minibutton" title="Preview this Page">Preview</a>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
{{#allow_editing}}
|
||||
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{edit_path}}/{{escaped_url_path}}"
|
||||
class="action-edit-page">Edit Page</a></li>
|
||||
{{/allow_editing}}
|
||||
</ul>
|
||||
@@ -21,7 +21,7 @@
|
||||
</ul>
|
||||
|
||||
<form name="compare-versions" id="version-form" method="post"
|
||||
action="{{base_url}}/compare/{{escaped_url_path}}">
|
||||
action="{{compare_path}}/{{escaped_url_path}}">
|
||||
<fieldset>
|
||||
<table>
|
||||
<tbody>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<a href="javascript:void(0)">
|
||||
<img src="{{#image_path_mustache}}man_24.png{{/image_path_mustache}}" alt="avatar: {{author}}"
|
||||
<img src="{{#sprockets_image_path}}man_24.png{{/sprockets_image_path}}" alt="avatar: {{author}}"
|
||||
class="mini-gravatar identicon" data-identicon="{{identicon}}"/>
|
||||
<span class="username">{{author}}</span>
|
||||
</a>
|
||||
@@ -5,13 +5,13 @@
|
||||
<meta name="MobileOptimized" content="width">
|
||||
<meta name="HandheldFriendly" content="true">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
{{#stylesheet_tag_mustache}}app media: :all{{/stylesheet_tag_mustache}}
|
||||
{{#stylesheet_tag_mustache}}print media: :print{{/stylesheet_tag_mustache}}
|
||||
{{#sprockets_stylesheet_tag}}app{{/sprockets_stylesheet_tag}}
|
||||
{{#sprockets_stylesheet_tag}}print print{{/sprockets_stylesheet_tag}}
|
||||
{{#css}}<link rel="stylesheet" type="text/css" href="{{custom_path}}/custom.css" media="all">{{/css}}
|
||||
{{#noindex}}<meta name="robots" content="noindex, nofollow" />{{/noindex}}
|
||||
|
||||
<!--[if lte IE 8]>
|
||||
{{#stylesheet_tag_mustache}}ie7 media: :all{{/stylesheet_tag_mustache}}
|
||||
{{#sprockets_stylesheet_tag}}ie7{{/sprockets_stylesheet_tag}}
|
||||
<![endif]-->
|
||||
|
||||
<script>
|
||||
@@ -21,9 +21,9 @@
|
||||
var pageFullPath = '{{url_path}}';
|
||||
{{/page}}
|
||||
</script>
|
||||
{{#javascript_tag_mustache}}app{{/javascript_tag_mustache}}
|
||||
{{#sprockets_javascript_tag}}app{{/sprockets_javascript_tag}}
|
||||
{{#use_identicon}}
|
||||
{{#javascript_tag_mustache}}identicon_canvas{{/javascript_tag_mustache}}
|
||||
{{#sprockets_javascript_tag}}identicon_canvas{{/sprockets_javascript_tag}}
|
||||
{{/use_identicon}}
|
||||
{{#mathjax}}
|
||||
{{^mathjax_config}}
|
||||
|
||||
@@ -14,7 +14,7 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
</li>
|
||||
<li class="minibutton"><a href="{{base_url}}/"
|
||||
class="action-home-page">Home</a></li>
|
||||
<li class="minibutton"><a href="{{base_url}}/pages"
|
||||
<li class="minibutton"><a href="{{pages_path}}"
|
||||
class="action-all-pages">Overview</a></li>
|
||||
{{#allow_editing}}
|
||||
<li class="minibutton jaws">
|
||||
@@ -34,13 +34,13 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
{{/allow_editing}}
|
||||
{{#allow_editing}}
|
||||
{{#editable}}
|
||||
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{edit_path}}/{{escaped_url_path}}"
|
||||
class="action-edit-page">Edit</a></li>
|
||||
{{/editable}}
|
||||
{{/allow_editing}}
|
||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||
class="action-page-history">History</a></li>
|
||||
<li class="minibutton"><a href="{{base_url}}/latest_changes"
|
||||
<li class="minibutton"><a href="{{latest_changes_path}}"
|
||||
class="action-page-history">Latest Changes</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -91,7 +91,7 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form name="rename" method="POST" action="{{base_url}}/rename/{{escaped_url_path}}">
|
||||
<form name="rename" method="POST" action="{{rename_path}}/{{escaped_url_path}}">
|
||||
<input type="hidden" name="rename"/>
|
||||
<input type="hidden" name="message"/>
|
||||
</form>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div id="searchbar">
|
||||
<form action="{{base_url}}/search" method="get" id="search-form">
|
||||
<form action="{{search_path}}" method="get" id="search-form">
|
||||
<div id="searchbar-fauxtext">
|
||||
<input type="text" name="q" id="search-query" value="Search…" autocomplete="off">
|
||||
<a href="#" id="search-submit" title="Search this wiki">
|
||||
|
||||
+50
-18
@@ -2,31 +2,63 @@ require 'yaml'
|
||||
|
||||
module Precious
|
||||
module Views
|
||||
module RouteHelpers
|
||||
ROUTES = {
|
||||
'gollum' => {
|
||||
last_commit_info: 'last-commit-info',
|
||||
latest_changes: 'latest_changes',
|
||||
upload_file: 'uploadFile',
|
||||
create: 'create',
|
||||
delete: 'delete',
|
||||
edit: 'edit',
|
||||
pages: 'pages',
|
||||
history: 'history',
|
||||
rename: 'rename',
|
||||
preview: 'preview',
|
||||
compare: 'compare',
|
||||
search: 'search'
|
||||
}
|
||||
}
|
||||
|
||||
def self.parse_routes(routes, prefix = '')
|
||||
routes.each do |name, path|
|
||||
if path.respond_to?(:keys)
|
||||
self.parse_routes(path, "#{prefix}/#{name}")
|
||||
else
|
||||
define_method :"#{name.to_s}_path" do
|
||||
"#{base_url}/#{prefix}/#{path}".gsub(/\/{2,}/, '/') # remove double slashes
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.included(base)
|
||||
self.parse_routes(ROUTES)
|
||||
end
|
||||
end
|
||||
|
||||
module SprocketsHelpers
|
||||
def self.included(base)
|
||||
|
||||
def helper_proc_with_options(method)
|
||||
Proc.new do |args|
|
||||
def sprockets_stylesheet_tag
|
||||
lambda do |args|
|
||||
args = args.split(' ')
|
||||
if args.size > 1 then
|
||||
options = args[1..-1].join(' ')
|
||||
options = YAML.safe_load("---\n#{options}\n", [Symbol])
|
||||
end
|
||||
options = options.respond_to?(:to_h) ? options.to_h : {}
|
||||
options = options.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
send(method, args[0], options)
|
||||
end
|
||||
end
|
||||
|
||||
['stylesheet_path','javascript_path', 'image_path'].each do |method|
|
||||
define_method :"#{method}_mustache" do
|
||||
Proc.new {|args| send(method.to_sym, args)}
|
||||
name = args[0]
|
||||
options = {:media => :all}
|
||||
options[:media] = :print if args[1] == 'print'
|
||||
send(:stylesheet_tag, name, options)
|
||||
end
|
||||
end
|
||||
|
||||
['stylesheet_tag','javascript_tag'].each do |method|
|
||||
define_method :"#{method}_mustache" do
|
||||
helper_proc_with_options(method.to_sym)
|
||||
def sprockets_javascript_tag
|
||||
lambda do |name|
|
||||
send(:javascript_tag, name)
|
||||
end
|
||||
end
|
||||
|
||||
def sprockets_image_path
|
||||
lambda do |args|
|
||||
send(:image_path, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,8 @@ module Precious
|
||||
include Rack::Utils
|
||||
include Sprockets::Helpers
|
||||
include Precious::Views::SprocketsHelpers
|
||||
include Precious::Views::RouteHelpers
|
||||
|
||||
alias_method :h, :escape_html
|
||||
|
||||
attr_reader :name, :path
|
||||
|
||||
@@ -49,7 +49,7 @@ module Precious
|
||||
# result contains a folder
|
||||
folder = result_path.split('/').first
|
||||
folder_path = @path ? "#{@path}/#{folder}" : folder
|
||||
folder_link = %{<li><a href="#{@base_url}/pages/#{folder_path}/" class="folder">#{folder}</a></li>}
|
||||
folder_link = %{<li><a href="#{pages_path}/#{folder_path}/" class="folder">#{folder}</a></li>}
|
||||
|
||||
folders[folder] = folder_link unless folders.key?(folder)
|
||||
elsif result_path != ".gitkeep"
|
||||
|
||||
Reference in New Issue
Block a user