Permalink
Browse files

Revamp configuration

  • Loading branch information...
1 parent 7cbd081 commit 5c02cf6dd0feb4fa86a497b1523371c53c5552ae Loren Segal committed Aug 22, 2013
View
16 app.rb
@@ -3,7 +3,6 @@
require 'yard'
require 'sinatra'
require 'json'
-require 'yaml'
require 'fileutils'
require 'airbrake'
@@ -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
@@ -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"
@@ -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
View
@@ -5,6 +5,7 @@
require 'rubygems'
require 'bundler/setup'
+require 'yaml'
require 'yard'
require 'yard-sd'
require 'yard-rails'
@@ -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
View
@@ -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
@@ -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>
@@ -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>
@@ -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.