Permalink
Browse files

Remove actionpack and activesupport dependencies.

  • Loading branch information...
1 parent 8d2c78e commit 5901b547cf61f06c6a27fbd8d8f5b29ccd039896 Bruce Williams committed Dec 8, 2009
View
@@ -0,0 +1,52 @@
+require 'rubygems'
+require 'rake'
+
+dependencies = %w(maruku nokogiri erubis)
+
+namespace :install do
+ dependencies.each do |dep|
+ desc "Install '#{dep}' dependency"
+ task dep do
+ sh "gem install #{dep} --no-rdoc --no-ri"
+ end
+ end
+end
+
+desc "Install dependencies"
+task :install => dependencies.map { |d| "install:#{d}" }
+
+desc "Generate the documentation"
+task :generate do
+ sh "bin/generate"
+end
+
+desc "Serve generated output on port 9292 (requires 'rack')"
+task :serve do
+ sh "rackup"
+end
+
+desc "Generate docs and serve locally"
+task :run => [:generate, :serve]
+
+
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+Spec::Rake::SpecTask.new(:rcov) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
+end
+
+task :default => :spec
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "puppet-docs"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
@@ -1,15 +1,6 @@
#!/usr/bin/env ruby
-require 'pathname'
-root = Pathname.new(__FILE__) + '../..'
-
-begin
- require root + 'vendor/gems/environment.rb'
-rescue LoadError
- abort "Make sure you have the 'bundler' gem installed, then run `gem bundle` first."
-end
-
-$LOAD_PATH.unshift(root + 'lib')
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'puppet_docs'
PuppetDocs::Generator.new.generate
View
@@ -1,15 +1,6 @@
#!/usr/bin/env ruby
-require 'pathname'
-root = Pathname.new(__FILE__) + '../..'
-
-begin
- require root + 'vendor/gems/environment.rb'
-rescue LoadError
- abort "Make sure you have the 'bundler' gem installed, then run `gem bundle` first."
-end
-
-$LOAD_PATH.unshift(root + 'lib')
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'puppet_docs'
PuppetDocs::Reference::Generator.new(*ARGV).generate
View
@@ -0,0 +1,24 @@
+require 'pathname'
+
+class DirectoryIndex
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ %w(REQUEST_METHOD REQUEST_URI PATH_INFO).each do |name|
+ value = env[name]
+ if value && value =~ /\/$/
+ value << 'index.html'
+ end
+ end
+ @app.call(env)
+ end
+
+end
+
+puts ">>> Serving at http://localhost:9292"
+
+use DirectoryIndex
+run Rack::Directory.new(Pathname.new(__FILE__).parent + 'output')
View
@@ -1,13 +1,15 @@
-# Loading Action Pack requires rack and erubis.
require 'rubygems'
+
require 'set'
-require 'maruku'
-require 'nokogiri'
require 'pathname'
-require 'actionpack'
-require 'action_controller'
-require 'action_view'
+%w(maruku nokogiri erubis).each do |dep|
+ begin
+ require dep
+ rescue LoadError
+ abort "Could not require '#{dep}'.\nRun `rake install:#{dep}` (or `rake install`)"
+ end
+end
module PuppetDocs
@@ -20,5 +22,13 @@ def self.root
autoload :Helpers, "puppet_docs/helpers"
autoload :Levenshtein, "puppet_docs/levenshtein"
autoload :Snippet, "puppet_docs/snippet"
+ autoload :View, "puppet_docs/view"
+ autoload :StringExt, "puppet_docs/string_ext"
end
+
+class String
+ include PuppetDocs::StringExt
+end
+
+
@@ -54,28 +54,23 @@ def generate_guide(guide)
planned_path = File.join(output, File.dirname(rel_path), slug) + '.html'
FileUtils.mkdir_p(File.dirname(planned_path)) rescue nil
+
+ view = View.new(:to_root => '../' * rel_path.scan(/\//).size)
+
File.open(planned_path, 'w') do |f|
- @view = ActionView::Base.new(view_path)
- @view.extend(Helpers)
- @view.instance_variable_set(:@to_root, '../' * rel_path.scan(/\//).size)
-
- if guide =~ /\.markdown\.erb$/
- body = view.render(
- :layout => false,
- :inline => File.read(guide),
- :locals => {:page => Pathname.new(guide)})
- else
- body = File.read(guide)
- end
- title, body = set_header_section(name, body, @view)
+
+ body = raw_body(guide, view)
+
+ title, body = set_header_section(name, body, view)
unless title && body
puts "Skipping..."
next
end
body = add_snippets(body)
body = add_extras(body)
- body = set_index(title, body, @view)
- result = view.render(:layout => 'layout', :text => markdown(body, true).html_safe!)
+ body = set_index(title, body, view)
+
+ result = view.render(markdown(body, true).html_safe!)
f.write result
warn_about_broken_links(result) if ENV.key?("WARN_BROKEN_LINKS")
end
@@ -90,8 +85,8 @@ def set_header_section(name, body, view)
page_title = name.titleize
end
header = markdown(header)
- view.content_for(:page_title) { page_title.html_safe! }
- view.content_for(:header_section) { header.html_safe! }
+ view.set(:page_title, page_title.html_safe!)
+ view.set(:header_section, header.html_safe!)
[page_title, new_body]
else
puts "Did not provide a prologue separator."
@@ -102,7 +97,7 @@ def set_header_section(name, body, view)
def set_index(title, body, view)
index = <<-INDEX
<div id="subCol">
- <h3 class="chapter"><img src="#{@view.instance_variable_get(:@to_root)}images/chapters_icon.gif" alt="" />Contents</h3>
+ <h3 class="chapter"><img src="#{view[:to_root]}images/chapters_icon.gif" alt="" />Contents</h3>
<ol class="chapters">
INDEX
@@ -114,11 +109,22 @@ def set_index(title, body, view)
index << '</ol>'
index << '</div>'
- view.content_for(:index_section) { index.html_safe! }
+ view.set(:index_section, index.html_safe!)
body
end
+ def raw_body(path, view)
+ body = File.read(path)
+ if path =~ /\.markdown\.erb$/
+ raw_content = File.read(path)
+ view.set_local :page, Pathname.new(path)
+ view.render(body, :layout => false)
+ else
+ body
+ end
+ end
+
def markdown(body, include_settings = false)
body = settings_content + body if include_settings
Maruku.new(body).to_html
View
@@ -1,34 +1,11 @@
module PuppetDocs
module Helpers
- def guide(name, url, options = {}, &block)
- link = content_tag(:a, :href => url) { name }
- result = content_tag(:dt, link)
- if ticket = options[:ticket]
- result << content_tag(:dd, lh(ticket), :class => 'ticket')
- end
-
- result << content_tag(:dd, capture(&block))
- concat(result)
- end
-
- def lh(id, label = "Lighthouse Ticket")
- url = "http://rails.lighthouseapp.com/projects/16213/tickets/#{id}"
- content_tag(:a, label, :href => url)
+ def ticket(n, text = nil, project = 'puppet')
+ url = "http://projects.reductivelabs.com/projects/#{project}/tickets/#{n}"
+ inner = text ? text : "Ticket ##{n}"
+ %{<a href="#{url}">#{inner}</a>}
end
- def author(name, nick, image = 'credits_pic_blank.gif', &block)
- image = "images/#{image}"
-
- result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name)
- result << content_tag(:h3, name)
- result << content_tag(:p, capture(&block))
- concat content_tag(:div, result, :class => 'clearfix', :id => nick)
- end
-
- def code(&block)
- c = capture(&block)
- content_tag(:code, c)
- end
end
end
@@ -34,18 +34,9 @@ def install
def prologue
title = "#{@name.capitalize} Reference (#{version})\n========================\n\n"
separator = "\n\n* * *\n\n"
- if File.exist?(prologue_filename)
- template = ERB.new(File.read(prologue_filename))
- title + template.result(binding) + separator
- else
- title + separator
- end
- end
-
- def prologue_filename
- @prologue_filename ||= PuppetDocs.root + "reference-prologues/#{@name}.erb"
+ title + separator
end
-
+
def valid_tags
@valid_tags ||= at('master') { `git tag` }.grep(/\./).map { |s| s.strip }
end
@@ -0,0 +1,19 @@
+module PuppetDocs
+
+ module StringExt
+
+ def underscore
+ to_s.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
+
+ def titleize
+ underscore.gsub(/\b('?[a-z])/) { $1.capitalize }
+ end
+
+ end
+
+end
View
@@ -0,0 +1,69 @@
+module PuppetDocs
+
+ class View
+
+ def self.layout
+ @layout ||=
+ if default_layout_path.exist?
+ default_layout_path.read
+ end
+ end
+
+ def self.layout=(text)
+ @layout = text
+ end
+
+ def self.default_layout_path
+ PuppetDocs.root + "source/layout.html.erb"
+ end
+
+ def self.render_defaults
+ @render_defaults ||= {:layout => true}
+ end
+
+ def initialize(data = {})
+ @data = Erubis::Context.new(data)
+ class << @data; include PuppetDocs::Helpers; end
+ end
+
+ def set(name, value)
+ @data[name] = value
+ end
+
+ def set_local(name, value)
+ set(name, value)
+ (class << @data; self; end).instance_eval "attr_reader :#{name}"
+ end
+
+ def [](name)
+ @data[name]
+ end
+
+ def render(*args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ options = self.class.render_defaults.merge(options)
+ text = args.shift
+ result = Erubis::Eruby.new(text).evaluate(@data, &data_access(nil))
+ if options[:layout]
+ if self.class.layout
+ result = Erubis::Eruby.new(self.class.layout).evaluate(@data, &data_access(result))
+ end
+ end
+ result
+ end
+
+ private
+
+ def data_access(text = nil)
+ proc do |*sections|
+ if !sections.empty?
+ @data[sections.first]
+ else
+ text
+ end
+ end
+ end
+
+ end
+
+end
File renamed without changes.
@@ -0,0 +1 @@
+<html><body><%= yield %></body></html>
View
@@ -0,0 +1 @@
+--color
Oops, something went wrong.

0 comments on commit 5901b54

Please sign in to comment.