mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-10-31 15:25:04 -04: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
f3978d1604
commit
9af3642100
5
Rakefile
5
Rakefile
@ -192,8 +192,9 @@ end
|
||||
|
||||
desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache"
|
||||
task :clean do
|
||||
[".pygments-cache/**", ".gist-cache/**", ".sass-cache/**"].each { |dir| rm_rf Dir.glob(dir) }
|
||||
rm "source/stylesheets/screen.css"
|
||||
[".pygments-cache/**", ".gist-cache/**"].each { |dir| rm_rf Dir.glob(dir) }
|
||||
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 ##"
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ code_dir: downloads/code
|
||||
category_dir: blog/categories
|
||||
category_title_prefix: "Category: "
|
||||
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
|
||||
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/config'
|
||||
require 'albino'
|
||||
require 'pygments'
|
||||
require 'fileutils'
|
||||
require 'digest/md5'
|
||||
@ -9,13 +10,17 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
|
||||
|
||||
module HighlightCode
|
||||
include TemplateWrapper
|
||||
include SiteConfig
|
||||
def pygments(code, lang)
|
||||
path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html") if defined?(PYGMENTS_CACHE_DIR)
|
||||
if File.exist?(path)
|
||||
highlighted_code = File.read(path)
|
||||
else
|
||||
#highlighted_code = Albino.new(code, lang, :html)
|
||||
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
|
||||
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'})
|
||||
end
|
||||
File.open(path, 'w') {|f| f.print(highlighted_code) } if path
|
||||
end
|
||||
highlighted_code.to_s
|
||||
|
Loading…
Reference in New Issue
Block a user