Module: Neapolitan
- Defined in:
- lib/neapolitan.rb,
lib/neapolitan/cli.rb,
lib/neapolitan/part.rb,
lib/neapolitan/factory.rb,
lib/neapolitan/version.rb,
lib/neapolitan/template.rb,
lib/neapolitan/rendering.rb
Defined Under Namespace
Classes: Factory, Part, Rendering, Template
Class Method Summary collapse
-
.cli(*argv) ⇒ Object
Command line interface.
-
.const_missing(name) ⇒ Object
Access project metadata as constants.
-
.file(fname, options = {}) ⇒ Object
Specifically create a new template from a file, given the files name.
-
.load(source, options = {}) ⇒ Object
Load template from given source.
-
.metadata ⇒ Object
Access to project metadata.
- .option_parser(options) ⇒ Object
-
.reject(&reject) ⇒ Object
Limit the section formats for all templates via a rejection procedure.
-
.select(&select) ⇒ Object
Limit the section formats for all templates to the sepecified selection via a selection procedure.
-
.system(libname = nil) ⇒ Object
Set default rendering system for all templates.
-
.text(source, options = {}) ⇒ Object
Specifically create a new template from a text string.
Class Method Details
.cli(*argv) ⇒ Object
Command line interface.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/neapolitan/cli.rb', line 4 def self.cli(*argv) = {} option_parser().parse!(argv) if src = [:source] data = YAML.load(File.new(src)) else data = {} #@source ||= YAML.load(STDIN.read) end files = argv begin files.each do |file| template = Template.new(File.new(file)) if [:output] #template.save(data) else puts template.render(data) end end rescue => e $DEBUG ? raise(e) : puts(e.) end end |
.const_missing(name) ⇒ Object
Access project metadata as constants.
12 13 14 15 |
# File 'lib/neapolitan/version.rb', line 12 def self.const_missing(name) key = name.to_s.downcase [key] || super(name) end |
.file(fname, options = {}) ⇒ Object
Specifically create a new template from a file, given the files name.
71 72 73 |
# File 'lib/neapolitan.rb', line 71 def self.file(fname, ={}) Template.new(File.new(fname), ) end |
.load(source, options = {}) ⇒ Object
Load template from given source.
50 51 52 |
# File 'lib/neapolitan.rb', line 50 def self.load(source, ={}) Template.new(source, ) end |
.metadata ⇒ Object
Access to project metadata.
4 5 6 7 8 9 |
# File 'lib/neapolitan/version.rb', line 4 def self. @metadata ||= ( require 'yaml' YAML.load(File.new(File.dirname(__FILE__) + '/neapolitan.yml')) ) end |
.option_parser(options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/neapolitan/cli.rb', line 34 def self.option_parser() require 'optparse' OptionParser.new do |opt| opt. = "neapolitan [file1 file2 ...]" #opt.on("--output", "-o [PATH]", "save output to specified directory") do |path| # options[:output] = path #end opt.on("--source", "-s [FILE]", "data souce (YAML file)") do |file| [:source] = file end opt.on("--tilt", "use Tilt for rendering instead of Malt") do [:tilt] = true end opt.on("--trace", "show extra operational information") do $TRACE = true end opt.on("--dryrun", "-n", "don't actually write to disk") do $DRYRUN = true end opt.on("--debug", "run in debug mode") do $DEBUG = true $VERBOSE = true end opt.on_tail("--help", "display this help message") do puts opt exit end end end |
.reject(&reject) ⇒ Object
Limit the section formats for all templates via a rejection procedure.
37 38 39 40 |
# File 'lib/neapolitan.rb', line 37 def self.reject(&reject) @reject = reject if reject @reject end |
.select(&select) ⇒ Object
Limit the section formats for all templates to the sepecified selection via a selection procedure.
30 31 32 33 |
# File 'lib/neapolitan.rb', line 30 def self.select(&select) @select = select if select @select end |
.system(libname = nil) ⇒ Object
Set default rendering system for all templates.
This can either be :tilt or :malt, the default.
23 24 25 26 |
# File 'lib/neapolitan.rb', line 23 def self.system(libname=nil) @system = libname if libname @system end |