Package assets (#1493)
* Package static assets * Fixed cancel button in editor * Fix rake compilation task * Add asset path helper * Serve MathJax statically * Fix mathjax in preview
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
(The MIT License)
|
(The MIT License)
|
||||||
|
|
||||||
Copyright (c) Tom Preston-Werner, Rick Olson
|
Copyright (c) Tom Preston-Werner, Rick Olson, Dawa Ometto, Bart Kamphorst
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the 'Software'), to deal
|
of this software and associated documentation files (the 'Software'), to deal
|
||||||
|
|||||||
@@ -187,14 +187,15 @@ task :precompile do
|
|||||||
require 'sprockets-helpers'
|
require 'sprockets-helpers'
|
||||||
require 'sass'
|
require 'sass'
|
||||||
env = Precious::Assets.sprockets
|
env = Precious::Assets.sprockets
|
||||||
manifest = Sprockets::Manifest.new(env, './public/assets')
|
path = ENV.fetch('GOLLUM_ASSETS_PATH', ::File.join(File.dirname(__FILE__), 'lib/gollum/public/assets'))
|
||||||
|
manifest = Sprockets::Manifest.new(env, path)
|
||||||
Sprockets::Helpers.configure do |config|
|
Sprockets::Helpers.configure do |config|
|
||||||
config.environment = env
|
config.environment = env
|
||||||
config.prefix = Precious::Assets::ASSET_URL
|
config.prefix = Precious::Assets::ASSET_URL
|
||||||
config.digest = true
|
config.digest = true
|
||||||
config.public_path = ENV.fetch('GOLLUM_ASSETS_PATH', './public/assets')
|
config.public_path = path
|
||||||
config.manifest = manifest
|
config.manifest = manifest
|
||||||
end
|
end
|
||||||
puts "Precompiling assets to #{::File.expand_path('./public/assets')}..."
|
puts "Precompiling assets to #{path}..."
|
||||||
manifest.compile(Precious::Assets::MANIFEST)
|
manifest.compile(Precious::Assets::MANIFEST)
|
||||||
end
|
end
|
||||||
|
|||||||
+7
-6
@@ -51,7 +51,7 @@ opts = OptionParser.new do |opts|
|
|||||||
# don't use 'port.to_i' here... it doesn't raise errors which might result in a nice confusion later on
|
# don't use 'port.to_i' here... it doesn't raise errors which might result in a nice confusion later on
|
||||||
options[:port] = Integer(port)
|
options[:port] = Integer(port)
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
puts 'Error: '#{port}' is not a valid port number.'
|
puts "Error: '#{port}' is not a valid port number."
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -79,8 +79,8 @@ opts = OptionParser.new do |opts|
|
|||||||
unless base_path_original == base_path
|
unless base_path_original == base_path
|
||||||
puts <<MSG
|
puts <<MSG
|
||||||
Warning: your base-path has been sanitized:
|
Warning: your base-path has been sanitized:
|
||||||
- original: '#{base_path_original}'
|
- original: "#{base_path_original}"
|
||||||
- sanitized: '#{base_path}'
|
- sanitized: "#{base_path}"
|
||||||
MSG
|
MSG
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ MSG
|
|||||||
opts.on('--versions', 'Display the current version of Gollum and auxiliary gems.') do
|
opts.on('--versions', 'Display the current version of Gollum and auxiliary gems.') do
|
||||||
require 'gollum-lib'
|
require 'gollum-lib'
|
||||||
puts 'Gollum ' + Gollum::VERSION
|
puts 'Gollum ' + Gollum::VERSION
|
||||||
puts 'Running on: #{RUBY_PLATFORM} with Ruby version #{RUBY_VERSION}'
|
puts "Running on: #{RUBY_PLATFORM} with Ruby version #{RUBY_VERSION}"
|
||||||
puts 'Using:'
|
puts 'Using:'
|
||||||
loaded_gemspecs = Gem.loaded_specs
|
loaded_gemspecs = Gem.loaded_specs
|
||||||
gollum_gems = ['gollum-lib', 'gollum-rjgit_adapter', 'rjgit', 'gollum-rugged_adapter', 'rugged']
|
gollum_gems = ['gollum-lib', 'gollum-rjgit_adapter', 'rjgit', 'gollum-rugged_adapter', 'rugged']
|
||||||
@@ -197,8 +197,8 @@ end
|
|||||||
# Read command line options into `options` hash
|
# Read command line options into `options` hash
|
||||||
begin
|
begin
|
||||||
opts.parse!
|
opts.parse!
|
||||||
rescue OptionParser::InvalidOption
|
rescue OptionParser::InvalidOption => e
|
||||||
puts 'gollum: #{$!.message}'
|
puts "gollum: #{e.message}"
|
||||||
puts 'gollum: try \'gollum --help\' for more information'
|
puts 'gollum: try \'gollum --help\' for more information'
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
@@ -262,6 +262,7 @@ if options[:irb]
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
require 'gollum/app'
|
require 'gollum/app'
|
||||||
|
Precious::App.set(:environment, ENV.fetch('RACK_ENV', :production).to_sym)
|
||||||
Precious::App.set(:gollum_path, gollum_path)
|
Precious::App.set(:gollum_path, gollum_path)
|
||||||
Precious::App.set(:wiki_options, wiki_options)
|
Precious::App.set(:wiki_options, wiki_options)
|
||||||
Precious::App.settings.mustache[:templates] = wiki_options[:template_dir] if wiki_options[:template_dir]
|
Precious::App.settings.mustache[:templates] = wiki_options[:template_dir] if wiki_options[:template_dir]
|
||||||
|
|||||||
+9
-5
@@ -91,7 +91,8 @@ module Precious
|
|||||||
@mathjax_config = settings.wiki_options[:mathjax_config]
|
@mathjax_config = settings.wiki_options[:mathjax_config]
|
||||||
|
|
||||||
@use_static_assets = settings.wiki_options.fetch(:static, settings.environment == :production || settings.environment == :staging)
|
@use_static_assets = settings.wiki_options.fetch(:static, settings.environment == :production || settings.environment == :staging)
|
||||||
@static_assets_path = settings.wiki_options.fetch(:static_assets_path, './public/assets')
|
@static_assets_path = settings.wiki_options.fetch(:static_assets_path, ::File.join(File.dirname(__FILE__), 'public/assets'))
|
||||||
|
@mathjax_path = ::File.join(File.dirname(__FILE__), 'public/gollum/javascript/MathJax')
|
||||||
|
|
||||||
Sprockets::Helpers.configure do |config|
|
Sprockets::Helpers.configure do |config|
|
||||||
config.environment = settings.sprockets
|
config.environment = settings.sprockets
|
||||||
@@ -111,13 +112,16 @@ module Precious
|
|||||||
|
|
||||||
namespace '/gollum' do
|
namespace '/gollum' do
|
||||||
|
|
||||||
|
get '/assets/mathjax/*' do
|
||||||
|
env['PATH_INFO'].sub!("/gollum/assets/mathjax", '')
|
||||||
|
Rack::Static.new(not_found_proc, {:root => @mathjax_path, :urls => ['']}).call(env)
|
||||||
|
end
|
||||||
|
|
||||||
get '/assets/*' do
|
get '/assets/*' do
|
||||||
env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '')
|
env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '')
|
||||||
if @use_static_assets
|
if @use_static_assets
|
||||||
env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url
|
env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url
|
||||||
not_found_msg = 'Not found.'
|
Rack::Static.new(not_found_proc, {:root => @static_assets_path, :urls => ['']}).call(env)
|
||||||
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
|
else
|
||||||
settings.sprockets.call(env)
|
settings.sprockets.call(env)
|
||||||
end
|
end
|
||||||
@@ -168,6 +172,7 @@ module Precious
|
|||||||
if page = wikip.page
|
if page = wikip.page
|
||||||
@page = page
|
@page = page
|
||||||
@content = page.text_data
|
@content = page.text_data
|
||||||
|
@mathjax = wiki.mathjax
|
||||||
@etag = page.sha
|
@etag = page.sha
|
||||||
mustache :edit
|
mustache :edit
|
||||||
else
|
else
|
||||||
@@ -381,7 +386,6 @@ module Precious
|
|||||||
end
|
end
|
||||||
@content = @page.formatted_data
|
@content = @page.formatted_data
|
||||||
@toc_content = wiki.universal_toc ? @page.toc_data : nil
|
@toc_content = wiki.universal_toc ? @page.toc_data : nil
|
||||||
@mathjax = wiki.mathjax
|
|
||||||
@h1_title = wiki.h1_title
|
@h1_title = wiki.h1_title
|
||||||
@editable = false
|
@editable = false
|
||||||
@bar_side = wiki.bar_side
|
@bar_side = wiki.bar_side
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require 'octicons'
|
|||||||
|
|
||||||
module Precious
|
module Precious
|
||||||
module Assets
|
module Assets
|
||||||
MANIFEST = %w(app.js editor.js app.css criticmarkup.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)
|
MANIFEST = %w(app.js editor.js app.css criticmarkup.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf)
|
||||||
ASSET_URL = 'gollum/assets'
|
ASSET_URL = 'gollum/assets'
|
||||||
|
|
||||||
def self.sprockets(dir = File.dirname(File.expand_path(__FILE__)))
|
def self.sprockets(dir = File.dirname(File.expand_path(__FILE__)))
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ module Precious
|
|||||||
return mustache :error
|
return mustache :error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_found_proc
|
||||||
|
not_found_msg = 'Not found.'
|
||||||
|
Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]}
|
||||||
|
end
|
||||||
|
|
||||||
def emoji(name)
|
def emoji(name)
|
||||||
if emoji = Gemojione.index.find_by_name(name)
|
if emoji = Gemojione.index.find_by_name(name)
|
||||||
IO.read(EMOJI_PATHNAME.join("#{emoji['unicode'].downcase}.png"))
|
IO.read(EMOJI_PATHNAME.join("#{emoji['unicode'].downcase}.png"))
|
||||||
|
|||||||
+21
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
+5
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
+1
@@ -0,0 +1 @@
|
|||||||
|
.criticmarkup mark{background-color:#fffd38;text-decoration:none}.criticmarkup del{background-color:#f6a9a9;text-decoration:line-through}.criticmarkup ins{background-color:#a9f6a9;text-decoration:none}.criticmarkup ins.break{display:block;line-height:2px;padding:0 !important;margin:0 !important}.criticmarkup ins.break span{line-height:1.5em}.criticmarkup .popover{background-color:#fffd38;color:#000}.criticmarkup .critic.comment{display:none}.criticmarkup .popover:hover span.critic.comment{display:block;position:absolute;width:200px;left:30%;font-size:0.8em;color:#ccc;background-color:#333;z-index:10;padding:0.5em 1em;border-radius:0.5em}
|
||||||
BIN
Binary file not shown.
+24
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
+1
@@ -0,0 +1 @@
|
|||||||
|
ul.actions{display:none}#delete-link{display:none}div#footer{display:none}
|
||||||
BIN
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 939 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB |
@@ -29,9 +29,13 @@ offline with latex equations without bloating the gollum release tarball.
|
|||||||
|
|
||||||
cd MathJax-x.y.z && grunt && cd ..
|
cd MathJax-x.y.z && grunt && cd ..
|
||||||
|
|
||||||
7. Replace bundled mathjax with newly generated one
|
7. Remove old mathjax (careful!)
|
||||||
|
|
||||||
cp MathJax-x.y.z ${GOLLUM_ROOT}/lib/gollum/public/gollum/javascript
|
rm -rf ${GOLLUM_ROOT}/lib/gollum/public/gollum/javascript/MathJax
|
||||||
|
|
||||||
8. Update mathjax version in ${GOLLUM_ROOT}/lib/gollum/templates/layout.mustache
|
8. Replace bundled mathjax with newly generated one
|
||||||
|
|
||||||
|
cp MathJax-x.y.z ${GOLLUM_ROOT}/lib/gollum/public/gollum/javascript/MathJax
|
||||||
|
|
||||||
|
9. Update mathjax version in ${GOLLUM_ROOT}/lib/gollum/templates/layout.mustache
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user