Skip to content

Commit

Permalink
Revamp configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Aug 22, 2013
1 parent 7cbd081 commit 5c02cf6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
16 changes: 3 additions & 13 deletions app.rb
Expand Up @@ -3,7 +3,6 @@
require 'yard'
require 'sinatra'
require 'json'
require 'yaml'
require 'fileutils'
require 'airbrake'

Expand Down Expand Up @@ -40,15 +39,9 @@ def self.load_configuration
set :whitelisted_gems, []
set :caching, false

return unless File.file?(CONFIG_FILE)

puts ">> Loading #{CONFIG_FILE}"
YAML.load_file(CONFIG_FILE).each do |key, value|
$CONFIG.each do |key, value|
set key, value
the_options[key.to_sym] = value
$DISQUS = value if key == 'disqus' # HACK for DISQUS setting
$CLICKY = value if key == 'clicky' # Hack for Clicky setting
$GOOGLE_ANALYTICS = value if key == 'google_analytics' # Hack for GA settings
end
end

Expand Down Expand Up @@ -100,10 +93,10 @@ def self.find_featured_yardoc(name, libdir)
end

def self.load_featured_adapter
raise(Errno::ENOENT) unless the_options.has_key?(:featured)
raise(Errno::ENOENT) unless $CONFIG.has_key?(:featured)
opts = adapter_options
opts[:options][:router] = FeaturedRouter
the_options[:featured].each do |key, value|
$CONFIG[:featured].each do |key, value|
opts[:libraries][key] = case value
when String
if value == "gem"
Expand Down Expand Up @@ -153,9 +146,6 @@ def self.post_all(*args, &block)
args.each {|arg| post(arg, &block) }
end

class << self; attr_accessor :the_options end
@the_options = {}

use Rack::Deflater
use Rack::ConditionalGet
use Rack::Head
Expand Down
7 changes: 7 additions & 0 deletions init.rb
Expand Up @@ -5,6 +5,7 @@

require 'rubygems'
require 'bundler/setup'
require 'yaml'
require 'yard'
require 'yard-sd'
require 'yard-rails'
Expand Down Expand Up @@ -33,3 +34,9 @@ def __p(*extra)
CONFIG_FILE = __p('config', 'config.yaml', :file)
REMOTE_GEMS_FILE = __p('data', 'remote_gems', :file)
RECENT_SQL_FILE = __p('data', 'recent.sqlite', :file)

require_relative 'lib/helpers'
require_relative 'lib/cache'
require_relative 'lib/configuration'

$CONFIG = Configuration.load
24 changes: 24 additions & 0 deletions lib/configuration.rb
@@ -0,0 +1,24 @@
class Configuration < Hash
def self.load
config = Configuration.new

if File.file?(CONFIG_FILE)
YAML.load_file(CONFIG_FILE).each do |key, value|
config[key] = value
define_method(key) { self[key] }
end
end

config
end

def caching_type
if caching; :disk
elsif varnish_host; :varnish
end
end

def method_missing(name, *args, &block)
self[name]
end
end
10 changes: 5 additions & 5 deletions templates/default/layout/html/footer.erb
Expand Up @@ -4,20 +4,20 @@
<%= YARD::VERSION %> (ruby-<%= RUBY_VERSION %>).
</div>

<% if $CLICKY %>
<% if $CONFIG.clicky %>
<script src="http://static.getclicky.com/js" type="text/javascript"></script>
<script type="text/javascript">clicky.init(<%= $CLICKY %>);</script>
<noscript><p><img alt="Clicky" width="1" height="1" src="http://static.getclicky.com/<%= $CLICKY %>ns.gif" /></p></noscript>
<script type="text/javascript">clicky.init(<%= $CONFIG.clicky %>);</script>
<noscript><p><img alt="Clicky" width="1" height="1" src="http://static.getclicky.com/<%= $CONFIG.clicky %>ns.gif" /></p></noscript>
<% end %>
<% if $GOOGLE_ANALYTICS %>
<% if $CONFIG.google_analytics %>
<script type='text/javascript'>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type='text/javascript'>
try {
var pageTracker = _gat._getTracker("<%= $GOOGLE_ANALYTICS %>");
var pageTracker = _gat._getTracker("<%= $CONFIG.google_analytics %>");
pageTracker._trackPageview();
} catch(err) {}
</script>
Expand Down
4 changes: 2 additions & 2 deletions templates/default/method/html/disqus.erb
Expand Up @@ -4,6 +4,6 @@
</script>
<h2>Comments</h2>
<div id="disqus_thread"></div>
<script type="text/javascript" src="http://disqus.com/forums/<%= $DISQUS %>/embed.js"></script>
<noscript><a href="http://disqus.com/forums/<%= $DISQUS %>/?url=ref">View the discussion thread.</a></noscript>
<script type="text/javascript" src="http://disqus.com/forums/<%= $CONFIG.disqus %>/embed.js"></script>
<noscript><a href="http://disqus.com/forums/<%= $CONFIG.disqus %>/?url=ref">View the discussion thread.</a></noscript>
</div>
2 changes: 1 addition & 1 deletion templates/default/method/setup.rb
@@ -1,5 +1,5 @@
def init
super
return unless defined? $DISQUS
return unless defined? $CONFIG.disqus
sections.push :disqus
end

0 comments on commit 5c02cf6

Please sign in to comment.