mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-12-24 16:38:49 -05:00
Added plugins/config.rb for reading and writing _config.yml. Added option to use Albino and default Python Pygments by setting pygments:true in _config.yml
This commit is contained in:
parent
0ce6655e02
commit
28e99b3c38
5
Rakefile
5
Rakefile
@ -192,8 +192,9 @@ end
|
|||||||
|
|
||||||
desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache"
|
desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache"
|
||||||
task :clean do
|
task :clean do
|
||||||
[".pygments-cache/**", ".gist-cache/**", ".sass-cache/**"].each { |dir| rm_rf Dir.glob(dir) }
|
[".pygments-cache/**", ".gist-cache/**"].each { |dir| rm_rf Dir.glob(dir) }
|
||||||
rm "source/stylesheets/screen.css"
|
rm "#{source_dir}/stylesheets/screen.css" if File.exists?("#{source_dir}/stylesheets/screen.css")
|
||||||
|
system "compass clean"
|
||||||
puts "## Cleaned Sass, Pygments and Gist caches, removed generated stylesheets ##"
|
puts "## Cleaned Sass, Pygments and Gist caches, removed generated stylesheets ##"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ plugins: plugins
|
|||||||
code_dir: downloads/code
|
code_dir: downloads/code
|
||||||
category_dir: blog/categories
|
category_dir: blog/categories
|
||||||
markdown: rdiscount
|
markdown: rdiscount
|
||||||
pygments: false # default python pygments have been replaced by pygments.rb
|
pygments: false # Jekyll's default Python Pygments have been replaced by pygments.rb. Set to true to use Albino + Pythong Pygments
|
||||||
|
|
||||||
paginate: 10 # Posts per page on the blog index
|
paginate: 10 # Posts per page on the blog index
|
||||||
pagination_dir: blog # Directory base for pagination URLs eg. /blog/page/2/
|
pagination_dir: blog # Directory base for pagination URLs eg. /blog/page/2/
|
||||||
|
19
plugins/config.rb
Normal file
19
plugins/config.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# read and write to the _config.yml
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
|
module SiteConfig
|
||||||
|
ConfigFile = File.expand_path "../_config.yml", File.dirname(__FILE__)
|
||||||
|
|
||||||
|
def get_config (key)
|
||||||
|
config_data = YAML::load(File.open(ConfigFile))
|
||||||
|
config_data[key]
|
||||||
|
end
|
||||||
|
def set_config (key, val)
|
||||||
|
old_val = get_config(key)
|
||||||
|
config = IO.read(ConfigFile)
|
||||||
|
config.sub!(/#{key}:\s*#{old_val}/, "#{key}: #{val}")
|
||||||
|
File.open(ConfigFile, 'w') do |f|
|
||||||
|
f.write config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,5 +1,6 @@
|
|||||||
#require 'albino'
|
|
||||||
require './plugins/raw'
|
require './plugins/raw'
|
||||||
|
require './plugins/config'
|
||||||
|
require 'albino'
|
||||||
require 'pygments'
|
require 'pygments'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
@ -9,13 +10,17 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
|
|||||||
|
|
||||||
module HighlightCode
|
module HighlightCode
|
||||||
include TemplateWrapper
|
include TemplateWrapper
|
||||||
|
include SiteConfig
|
||||||
def pygments(code, lang)
|
def pygments(code, lang)
|
||||||
path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html") if defined?(PYGMENTS_CACHE_DIR)
|
path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html") if defined?(PYGMENTS_CACHE_DIR)
|
||||||
if File.exist?(path)
|
if File.exist?(path)
|
||||||
highlighted_code = File.read(path)
|
highlighted_code = File.read(path)
|
||||||
else
|
else
|
||||||
#highlighted_code = Albino.new(code, lang, :html)
|
if get_config('pygments')
|
||||||
|
highlighted_code = Albino.new(code, lang, :html)
|
||||||
|
else
|
||||||
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
|
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
|
||||||
|
end
|
||||||
File.open(path, 'w') {|f| f.print(highlighted_code) } if path
|
File.open(path, 'w') {|f| f.print(highlighted_code) } if path
|
||||||
end
|
end
|
||||||
highlighted_code.to_s
|
highlighted_code.to_s
|
||||||
|
Loading…
Reference in New Issue
Block a user