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)
|
||||
|
||||
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
|
||||
of this software and associated documentation files (the 'Software'), to deal
|
||||
|
||||
@@ -187,14 +187,15 @@ task :precompile do
|
||||
require 'sprockets-helpers'
|
||||
require 'sass'
|
||||
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|
|
||||
config.environment = env
|
||||
config.prefix = Precious::Assets::ASSET_URL
|
||||
config.digest = true
|
||||
config.public_path = ENV.fetch('GOLLUM_ASSETS_PATH', './public/assets')
|
||||
config.public_path = path
|
||||
config.manifest = manifest
|
||||
end
|
||||
puts "Precompiling assets to #{::File.expand_path('./public/assets')}..."
|
||||
puts "Precompiling assets to #{path}..."
|
||||
manifest.compile(Precious::Assets::MANIFEST)
|
||||
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
|
||||
options[:port] = Integer(port)
|
||||
rescue ArgumentError
|
||||
puts 'Error: '#{port}' is not a valid port number.'
|
||||
puts "Error: '#{port}' is not a valid port number."
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
@@ -79,8 +79,8 @@ opts = OptionParser.new do |opts|
|
||||
unless base_path_original == base_path
|
||||
puts <<MSG
|
||||
Warning: your base-path has been sanitized:
|
||||
- original: '#{base_path_original}'
|
||||
- sanitized: '#{base_path}'
|
||||
- original: "#{base_path_original}"
|
||||
- sanitized: "#{base_path}"
|
||||
MSG
|
||||
end
|
||||
|
||||
@@ -171,7 +171,7 @@ MSG
|
||||
opts.on('--versions', 'Display the current version of Gollum and auxiliary gems.') do
|
||||
require 'gollum-lib'
|
||||
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:'
|
||||
loaded_gemspecs = Gem.loaded_specs
|
||||
gollum_gems = ['gollum-lib', 'gollum-rjgit_adapter', 'rjgit', 'gollum-rugged_adapter', 'rugged']
|
||||
@@ -197,8 +197,8 @@ end
|
||||
# Read command line options into `options` hash
|
||||
begin
|
||||
opts.parse!
|
||||
rescue OptionParser::InvalidOption
|
||||
puts 'gollum: #{$!.message}'
|
||||
rescue OptionParser::InvalidOption => e
|
||||
puts "gollum: #{e.message}"
|
||||
puts 'gollum: try \'gollum --help\' for more information'
|
||||
exit
|
||||
end
|
||||
@@ -262,6 +262,7 @@ if options[:irb]
|
||||
end
|
||||
else
|
||||
require 'gollum/app'
|
||||
Precious::App.set(:environment, ENV.fetch('RACK_ENV', :production).to_sym)
|
||||
Precious::App.set(:gollum_path, gollum_path)
|
||||
Precious::App.set(:wiki_options, wiki_options)
|
||||
Precious::App.settings.mustache[:templates] = wiki_options[:template_dir] if wiki_options[:template_dir]
|
||||
|
||||
+10
-6
@@ -91,8 +91,9 @@ module Precious
|
||||
@mathjax_config = settings.wiki_options[:mathjax_config]
|
||||
|
||||
@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|
|
||||
config.environment = settings.sprockets
|
||||
config.environment.context_class.class_variable_set(:@@base_url, @base_url)
|
||||
@@ -110,14 +111,17 @@ module Precious
|
||||
end
|
||||
|
||||
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
|
||||
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)
|
||||
Rack::Static.new(not_found_proc, {:root => @static_assets_path, :urls => ['']}).call(env)
|
||||
else
|
||||
settings.sprockets.call(env)
|
||||
end
|
||||
@@ -168,6 +172,7 @@ module Precious
|
||||
if page = wikip.page
|
||||
@page = page
|
||||
@content = page.text_data
|
||||
@mathjax = wiki.mathjax
|
||||
@etag = page.sha
|
||||
mustache :edit
|
||||
else
|
||||
@@ -381,7 +386,6 @@ module Precious
|
||||
end
|
||||
@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
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'octicons'
|
||||
|
||||
module Precious
|
||||
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'
|
||||
|
||||
def self.sprockets(dir = File.dirname(File.expand_path(__FILE__)))
|
||||
|
||||
@@ -33,7 +33,12 @@ module Precious
|
||||
status 404
|
||||
return mustache :error
|
||||
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)
|
||||
if emoji = Gemojione.index.find_by_name(name)
|
||||
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 |
@@ -28,10 +28,14 @@ offline with latex equations without bloating the gollum release tarball.
|
||||
6. Slimify mathjax
|
||||
|
||||
cd MathJax-x.y.z && grunt && cd ..
|
||||
|
||||
7. Remove old mathjax (careful!)
|
||||
|
||||
7. Replace bundled mathjax with newly generated one
|
||||
rm -rf ${GOLLUM_ROOT}/lib/gollum/public/gollum/javascript/MathJax
|
||||
|
||||
cp MathJax-x.y.z ${GOLLUM_ROOT}/lib/gollum/public/gollum/javascript
|
||||
8. Replace bundled mathjax with newly generated one
|
||||
|
||||
8. Update mathjax version in ${GOLLUM_ROOT}/lib/gollum/templates/layout.mustache
|
||||
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