Module: Quarto

Defined in:
lib/quarto.rb,
lib/quarto/config.rb,
lib/quarto/xml_doc.rb,
lib/quarto/children.rb,
lib/quarto/generator.rb,
lib/quarto/rendering.rb,
lib/quarto/url_helper.rb,
lib/quarto/transformer.rb,
lib/quarto/init_project.rb,
lib/quarto/rails_helper.rb,
lib/quarto/element_wrapper.rb,
lib/quarto/html_transformer.rb,
lib/quarto/transformation_helper.rb,
lib/quarto/inheritable_attributes.rb

Overview

Quarto is a Ruby framework for generating collections of documents from XML. Potential applications include web sites and e-books. It’s built on top of ERB and REXML.

Quarto was built with HTML output in mind, but there’s nothing to prevent you from outputting to any other format. You could even output to an interpolated scripting language like PHP.

Why Quarto?

Say you have a book in XML format, and you want to make a web site from it. You could transform it to HTML using XSLT. But what if you need logic that can’t be implemented in XSLT?

Enter Quarto. Instead of writing a series of XSLT sheets, you write ERB templates. You implement whatever custom logic you need in classes that wrap the DOM elements, then you pass variables to the templates.

Installation

gem sources -a http://gems.github.com
sudo gem install jarrett-quarto

Using Quarto

Thorough documentation doesn’t exist yet. For now, see spec/sample_project and the RDoc.

Defined Under Namespace

Modules: ElementWrapper, InheritableAttributes, RailsHelper, TransformationHelper, UrlHelper Classes: Generator, HtmlTransformer, Rendering, Transformer, UnrecognizedElementError

Constant Summary collapse

PROJECT_SUBFOLDERS =
[
	'layouts',
	'models',
	'output',
	'pages',
	'xml',
	'transformers'
]
STARTER_GENERATE_FILE =
%q(
Quarto.generate do
	# Your code here
	# e.g.:
	# render 'companies.html.erb', '', 'companies.html', :companies => Company.find(:all)
end
)
STARTER_URLS_FILE =
%q(
module Quarto
	module ProjectUrls
		include Quarto::UrlHelper
		
		
	end
end
)

Class Method Summary collapse

Class Method Details

.config(configs_to_merge = nil) ⇒ Object

:nodoc:



4
5
6
7
8
9
# File 'lib/quarto/config.rb', line 4

def self.config(configs_to_merge = nil) # :nodoc:
	if configs_to_merge.is_a?(Hash)
		@config.merge!(configs_to_merge)
	end
	@config
end

.generate(project_path = nil, &block) ⇒ Object

Generates the project according to the directives in the block. A block must be supplied. The block will be evaluated within the context of a Quarto::Generator object.

If the optional project_path is given, the directives in the block willl be process for the project residing project_path. Otherwise, the current working directory will be used.

This method is typically called from generate.rb. There’s probably no reason for you to call it from any other context.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/quarto/generator.rb', line 12

def self.generate(project_path = nil, &block)
	unless block_given?
		raise ArgumentError, 'Quarto.generate must be given a block'
	end
	# caller[0] returns the trace for the context that called generate. So, if generate.rb is invoked directly, Quarto will still work.
	trace = caller()
	unless trace.empty?
		calling_file = trace[0].split(':')[-2]
		if File.basename(calling_file) == 'generate.rb'
			project_path = project_path || File.expand_path(File.dirname(calling_file))
		end
	end
	unless project_path.is_a?(String) and !project_path.empty?
		raise ArgumentError, 'project_path is required when Quarto.generate is called from any file other than generate.rb'
	end
	Dir.glob(project_path + '/models/*.rb').each do |model_file|
		require File.expand_path(model_file)
	end
	Dir.glob(project_path + '/transformers/*.rb').each do |transformer_file|
		require transformer_file
	end
	generator = Quarto::Generator.new(project_path)
	generator.generate(&block)
	generator
end

.generate_from_project_path(project_path) ⇒ Object

Generates the project at the specified path using its generate.rb.

Raises:

  • (ArgumentError)


39
40
41
42
# File 'lib/quarto/generator.rb', line 39

def self.generate_from_project_path(project_path)
	raise ArgumentError, "Expected string, but got #{project_path.inspect}" unless project_path.is_a?(String) and !project_path.empty?
	load(project_path + '/generate.rb')
end

.init_project(project_path) ⇒ Object

Initialize a new Quarto project at the specified path. Creates a generate.rb file and the necessary subfolders.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/quarto/init_project.rb', line 29

def self.init_project(project_path)
	raise ArgumentError, "Expected string, but got #{project_path.inspect}" unless project_path.is_a?(String) and !project_path.empty?
	project_path = File.expand_path(project_path)
	unless File.exists?(project_path)
		Dir.mkdir project_path
	end
	PROJECT_SUBFOLDERS.each do |subfolder|
		subfolder = project_path + '/' + subfolder
		unless File.exists?(subfolder)
			Dir.mkdir subfolder
		end
	end
	generate_file = project_path + '/generate.rb'
	unless File.exists?(generate_file)
		File.open(generate_file, 'w') do |file|
			file.print(STARTER_GENERATE_FILE)
		end
	end
	urls_file = project_path + '/urls.rb'
	unless File.exists?(urls_file)
		File.open(urls_file, 'w') do |file|
			file.print(STARTER_URLS_FILE)
		end
	end
	true
end

.xml_docObject

:nodoc:



7
8
9
# File 'lib/quarto/xml_doc.rb', line 7

def self.xml_doc # :nodoc:
	@xml_doc
end

.xml_source=(source) ⇒ Object

:nodoc:

Raises:

  • (ArgumentError)


2
3
4
5
# File 'lib/quarto/xml_doc.rb', line 2

def self.xml_source=(source) # :nodoc:
	raise ArgumentError, "Expected File but got #{source.inspect}" unless source.is_a?(File)
	@xml_doc = REXML::Document.new(source)
end