class MrHyde::Builder
Public Class Methods
load( code, opts={} )
click to toggle source
# File lib/mrhyde/builder.rb, line 12 def self.load( code, opts={} ) builder = Builder.new( opts ) builder.instance_eval( code ) builder end
load_file( path, opts={} )
click to toggle source
# File lib/mrhyde/builder.rb, line 7 def self.load_file( path, opts={} ) code = File.read_utf8( path ) self.load( code, opts ) end
new( opts={} )
click to toggle source
# File lib/mrhyde/builder.rb, line 21 def initialize( opts={} ) puts "starting new MrHyde script (sitefile) #{opts.inspect}; lets go" @test = opts[:dry_run] || opts[:test] || false @output_dir = opts[:o] || '.' end
Public Instance Methods
config( opts={} ) { |c| ... }
click to toggle source
# File lib/mrhyde/builder.rb, line 65 def config( opts={} ) puts " handle config block" c = Quik::OpenConfig.new yield( c ) ## pp c h = c.to_h ## # check for site.url if present also # add site.baseurl|path site_url = h['url'] if site_url.nil? || site_url.empty? ## special case site_url is empty string "" ## note: always add site url for now ## todo/fix: warn if we overwrite "empty" site.url - why? why not? h['url'] = 'http://example.com' # note: no trailing slash (/) e.g. example.com/ h['baseurl'] = '' # note: no trailing slash (/) e.g. / h['path'] = '' # (better) alias for baseurl else ## site_baseurl = h['baseurl'] ## site_path = h['path'] ### calculate path/baseurl url = URI.parse( site_url ) path = url.path.sub(/\/$/, '' ) ## note: cut off trailing slash if present e.g. '/' becomes '' h['baseurl'] = path h['path'] = path ## todo/fix: warn if we overwrite baseurl/path we new values - why? why not? end pp h if test? ## do nothing; dry run else org = YAML.load_file( "#{@output_dir}/#{@theme_key}/_config.yml" ) pp org ## for now always add props at the end ## improve later (patch using regex etc. - why? why not?) new_settings = YAML.dump( h ) ## note: cut off leading --- if present new_settings = new_settings.sub( /^-{3}\s*/, '') File.open( "#{@output_dir}/#{@theme_key}/_config.yml", "a" ) do |f| f.puts f.puts "######################################" f.puts "### Mr Hyde's Settings" f.puts f.puts new_settings end end end
install_theme( name, opts= {} )
click to toggle source
# File lib/mrhyde/builder.rb, line 33 def install_theme( name, opts= {} ) puts " handle install_theme #{name}, #{opts.inspect}" ## note for now assume name is key ## e.g. always downcase (e.g. Starter => starter) @theme_key = key = name.downcase ## themes_dir = "#{DrJekyll.root}/test/data" ## catalog = Catalog.new( "#{themes_dir}/themes.yml" ) url = "https://github.com/drjekyllthemes/themes/raw/master/themes.yml" puts "GET #{url}" ## todo - add color e.g. .bold.green if test? # do nothing; dry run else catalog = DrJekyll::Catalog.from_url( url ) theme = catalog.find( key ) if theme pak = DrJekyll::Package.new( key, theme ) ## todo/fix: ## add GET URL w/ color e.g. bright/bold green pak.download pak.unzip( "#{@output_dir}/#{key}" ) else ## todo: issue warning - why, why not?? fail "*** theme '#{key}' not found; sorry" end end end
output_dir()
click to toggle source
# File lib/mrhyde/builder.rb, line 30 def output_dir() @output_dir; end
test?()
click to toggle source
“global” builder options
# File lib/mrhyde/builder.rb, line 29 def test?() @test; end