Module: Mint
- Defined in:
- lib/mint/css.rb,
lib/mint/mint.rb,
lib/mint/style.rb,
lib/mint/layout.rb,
lib/mint/helpers.rb,
lib/mint/version.rb,
lib/mint/document.rb,
lib/mint/resource.rb,
lib/mint/exceptions.rb,
lib/mint/commandline.rb
Defined Under Namespace
Modules: CSS, CommandLine, Helpers Classes: Document, Layout, Resource, Style, TemplateNotFoundException
Constant Summary collapse
- VERSION =
'0.2.7'
Class Method Summary collapse
-
.css_formats ⇒ Object
Registered Css formats, for source -> destination name guessing/conversion only.
- .default_options ⇒ Object
-
.directories ⇒ Object
Returns a hash with key Mint directories.
-
.files ⇒ Object
Returns a hash with key Mint files.
-
.find_template(name, type) ⇒ Object
Finds a template named ‘name` in the Mint path.
-
.formats ⇒ Object
Returns a list of all file extensions that Tilt will render.
-
.guess_name_from(name) ⇒ Object
Guesses an appropriate name for the resource output file based on its source file’s base name.
-
.lookup_template(name_or_file, type = :layout) ⇒ Object
Decides whether the template specified by ‘name_or_file` is a real file or the name of a template.
-
.path(as_path = false) ⇒ Object
Return the an array with the Mint template path.
-
.path_for_scope(scope = :local, as_path = false) ⇒ Object
I want to refactor this so that Mint.path is always a Hash…
- .publish!(document) ⇒ Object
-
.renderer(path) ⇒ Object
Transforms a path into a template that will render the file specified at that path.
- .root ⇒ Object
-
.template?(file) ⇒ Boolean
A non-rigourous check to see if the file is somewhere on the MINT_PATH.
-
.templates ⇒ Object
Lists the full path for each known template in the Mint path.
Class Method Details
.css_formats ⇒ Object
Registered Css formats, for source -> destination name guessing/conversion only.
81 82 83 |
# File 'lib/mint/mint.rb', line 81 def self.css_formats css_formats = ['css', 'sass', 'scss', 'less'] end |
.default_options ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mint/mint.rb', line 63 def self. { # Do not set default `template`--will override style and # layout when already specified -- causes tricky bugs layout: 'default', # default layout style: 'default', # default style destination: nil, # do not create a subdirectory style_destination: nil # do not copy style to root } end |
.directories ⇒ Object
Returns a hash with key Mint directories
48 49 50 51 52 53 |
# File 'lib/mint/mint.rb', line 48 def self.directories { templates: 'templates', config: 'config' } end |
.files ⇒ Object
Returns a hash with key Mint files
56 57 58 59 60 61 |
# File 'lib/mint/mint.rb', line 56 def self.files { syntax: directories[:config] + '/syntax.yaml', config: directories[:config] + '/config.yaml' } end |
.find_template(name, type) ⇒ Object
Finds a template named ‘name` in the Mint path. If `type` is :layout, will look for `$MINT_PATH/templates/layout.*`. If it is :style, will look for `$MINT_PATH/templates/template_name/style.*`. Mint assumes that a named template will hold only one layout and one style template. It does not know how to decide between style.css and style.less, for example. For predictable results, only include one template file called `layout.*` in the `template_name` directory. Returns nil if it cannot find a template.
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/mint/mint.rb', line 120 def self.find_template(name, type) templates_dir = Mint.directories[:templates] file_name = lambda {|x| x + templates_dir + name + type.to_s } find_files = lambda {|x| Pathname.glob "#{x.to_s}.*" } acceptable = lambda {|x| x.to_s =~ /#{Mint.formats.join '|'}/ } template = Mint.path(true).map(&file_name).map(&find_files).flatten. select(&acceptable).select(&:exist?).first.to_s raise TemplateNotFoundException unless template template end |
.formats ⇒ Object
Returns a list of all file extensions that Tilt will render
75 76 77 |
# File 'lib/mint/mint.rb', line 75 def self.formats Tilt.mappings.keys end |
.guess_name_from(name) ⇒ Object
Guesses an appropriate name for the resource output file based on its source file’s base name
145 146 147 148 149 150 151 |
# File 'lib/mint/mint.rb', line 145 def self.guess_name_from(name) name = Pathname(name).basename if name css = Mint.css_formats.join '|' name.to_s. gsub(/\.(#{css})$/, '.css'). gsub(/(\.[^css]+)$/, '.html') end |
.lookup_template(name_or_file, type = :layout) ⇒ Object
Decides whether the template specified by ‘name_or_file` is a real file or the name of a template. If it is a real file, Mint will return a that file. Otherwise, Mint will look for a file with that name in the Mint path. The `type` argument indicates whether the template we are looking for is a layout or a style and will affect which type of template is returned for a given template name. For example, `lookup_template :normal` might return a layout template referring to the file ~/.mint/templates/normal/layout.erb. Adding :style as a second argument returns ~/.mint/templates/normal/style.css.
107 108 109 110 |
# File 'lib/mint/mint.rb', line 107 def self.lookup_template(name_or_file, type=:layout) name = name_or_file.to_s File.exist?(name) ? name : find_template(name, type) end |
.path(as_path = false) ⇒ Object
Return the an array with the Mint template path. Will first look for MINT_PATH environment variable. Otherwise will use smart defaults. Either way, earlier/higher paths take precedence. And is considered to be the directory for “local” config options, templates, etc.
23 24 25 26 27 28 |
# File 'lib/mint/mint.rb', line 23 def self.path(as_path=false) mint_path = ENV['MINT_PATH'] || "#{Dir.getwd}/.mint:~/.mint:#{Mint.root}" paths = mint_path.split(':') as_path ? paths.map {|p| Pathname.new(p). } : paths end |
.path_for_scope(scope = :local, as_path = false) ⇒ Object
I want to refactor this so that Mint.path is always a Hash… should take care of this in the Mint.path=() method. Right now, this is a hack. It assumes a sane MINT_PATH, where the first entry is most local, the second is user-level, and the last entry is most global.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mint/mint.rb', line 35 def self.path_for_scope(scope=:local, as_path=false) case Mint.path when Array index = { local: 0, user: 1, global: 2 }[scope] Mint.path(as_path)[index] when Hash Mint.path(as_path)[scope] else nil end end |
.publish!(document) ⇒ Object
159 160 161 |
# File 'lib/mint/mint.rb', line 159 def self.publish!(document) document.publish! end |
.renderer(path) ⇒ Object
Transforms a path into a template that will render the file specified at that path
155 156 157 |
# File 'lib/mint/mint.rb', line 155 def self.renderer(path) Tilt.new path.to_s, :smart => true, :ugly => true end |
.root ⇒ Object
15 16 17 |
# File 'lib/mint/mint.rb', line 15 def self.root (Pathname.new(__FILE__).realpath.dirname + '../..').to_s end |
.template?(file) ⇒ Boolean
A non-rigourous check to see if the file is somewhere on the MINT_PATH
136 137 138 139 140 141 |
# File 'lib/mint/mint.rb', line 136 def self.template?(file) paths = Mint.path.map {|f| File. f } file_path = Pathname.new(file) file_path.exist? and file_path.dirname..to_s =~ /#{paths.join('|')}/ end |
.templates ⇒ Object
Lists the full path for each known template in the Mint path
87 88 89 90 91 92 93 94 95 |
# File 'lib/mint/mint.rb', line 87 def self.templates templates_dir = Mint.directories[:templates] Mint.path(true). map {|p| p + directories[:templates] }. select(&:exist?). map {|p| p.children.select(&:directory?).map(&:to_s) }. flatten end |