Add option for custom js (like custom css)
* Add a new 'js' flag to indicate you want to embed a file named 'custom.js' which should exist at the root of the wiki
This commit is contained in:
@@ -548,10 +548,12 @@ Note that filenames on windows must not contain any of the following characters
|
|||||||
|
|
||||||
Gollum optionally takes a `--config file`. See [config.rb](https://github.com/gollum/gollum/blob/master/config.rb) for an example.
|
Gollum optionally takes a `--config file`. See [config.rb](https://github.com/gollum/gollum/blob/master/config.rb) for an example.
|
||||||
|
|
||||||
## CUSTOM CSS
|
## CUSTOM CSS/JS
|
||||||
|
|
||||||
The `--css` flag will inject `custom.css` from the root of your git repository into each page. `custom.css` must be commited to git or you will get a 302 redirect to the create page.
|
The `--css` flag will inject `custom.css` from the root of your git repository into each page. `custom.css` must be commited to git or you will get a 302 redirect to the create page.
|
||||||
|
|
||||||
|
The `--js` flag will inject `custom.js` from the root of your git repository into each page. `custom.js` must be commited to git or you will get a 302 redirect to the create page.
|
||||||
|
|
||||||
## CONTRIBUTE
|
## CONTRIBUTE
|
||||||
|
|
||||||
If you'd like to hack on Gollum, start by forking the repo on GitHub:
|
If you'd like to hack on Gollum, start by forking the repo on GitHub:
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ opts = OptionParser.new do |opts|
|
|||||||
wiki_options[:css] = true
|
wiki_options[:css] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("--js", "Inject custom js. Uses custom.js from root repository") do
|
||||||
|
wiki_options[:js] = true
|
||||||
|
end
|
||||||
|
|
||||||
opts.on("--page-file-dir [PATH]", "Specify the sub directory for all page files (default: repository root).") do |path|
|
opts.on("--page-file-dir [PATH]", "Specify the sub directory for all page files (default: repository root).") do |path|
|
||||||
wiki_options[:page_file_dir] = path
|
wiki_options[:page_file_dir] = path
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ module Precious
|
|||||||
# above will detect base_path when it's used with map in a config.ru
|
# above will detect base_path when it's used with map in a config.ru
|
||||||
settings.wiki_options.merge!({ :base_path => @base_url })
|
settings.wiki_options.merge!({ :base_path => @base_url })
|
||||||
@css = settings.wiki_options[:css]
|
@css = settings.wiki_options[:css]
|
||||||
|
@js = settings.wiki_options[:js]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="{{base_url}}/css/template.css" media="all">
|
<link rel="stylesheet" type="text/css" href="{{base_url}}/css/template.css" media="all">
|
||||||
<link rel="stylesheet" type="text/css" href="{{base_url}}/css/_styles.css" media="all">
|
<link rel="stylesheet" type="text/css" href="{{base_url}}/css/_styles.css" media="all">
|
||||||
{{#css}}<link rel="stylesheet" type="text/css" href="{{base_url}}/custom.css" media="all">{{/css}}
|
{{#css}}<link rel="stylesheet" type="text/css" href="{{base_url}}/custom.css" media="all">{{/css}}
|
||||||
|
{{#js}}<script type="text/javascript" src="{{base_url}}/custom.js"></script>{{/js}}
|
||||||
<title>{{title}}</title>
|
<title>{{title}}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
(d.head || d.getElementsByTagName('head')[0]).appendChild(j);
|
(d.head || d.getElementsByTagName('head')[0]).appendChild(j);
|
||||||
}(document));
|
}(document));
|
||||||
</script>{{/mathjax}}
|
</script>{{/mathjax}}
|
||||||
|
{{#js}}<script type="text/javascript" src="{{base_url}}/custom.js"></script>{{/js}}
|
||||||
|
|
||||||
<title>{{title}}</title>
|
<title>{{title}}</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ module Precious
|
|||||||
@css
|
@css
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def js # custom js
|
||||||
|
@js
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -461,6 +461,30 @@ context "Frontend" do
|
|||||||
assert_equal 'jkl', author.email
|
assert_equal 'jkl', author.email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "do not add custom.js by default" do
|
||||||
|
page = 'nocustom'
|
||||||
|
text = 'nope none'
|
||||||
|
|
||||||
|
@wiki.write_page(page, :markdown, text,
|
||||||
|
{ :name => 'user1', :email => 'user1' });
|
||||||
|
|
||||||
|
get page
|
||||||
|
assert_no_match /custom.js/, last_response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
test "add custom.js if setting" do
|
||||||
|
Precious::App.set(:wiki_options, { :js => true })
|
||||||
|
page = 'yaycustom'
|
||||||
|
text = 'customized!'
|
||||||
|
|
||||||
|
@wiki.write_page(page, :markdown, text,
|
||||||
|
{ :name => 'user1', :email => 'user1' });
|
||||||
|
|
||||||
|
get page
|
||||||
|
assert_match /custom.js/, last_response.body
|
||||||
|
Precious::App.set(:wiki_options, { :js => nil })
|
||||||
|
end
|
||||||
|
|
||||||
def app
|
def app
|
||||||
Precious::App
|
Precious::App
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user