mint 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -73,8 +73,8 @@ Notes:
73
73
 
74
74
  1. If you specify a template name here, Mint will search its paths in order (see **The Mint Path** for more details) for a template with that name. A template file looks like the following:
75
75
 
76
- ${MINT_PATH}/templates/template_name/style.css
77
- ${MINT_PATH}/templates/template_name/layout.haml
76
+ MINT_PATH/templates/template_name/style.css
77
+ MINT_PATH/templates/template_name/layout.haml
78
78
 
79
79
  2. If you specify a template name that is also the name of an existing file in your working directory, Mint will use the file and not look for a template. (It is unlikely you'll have an extension-less file named 'normal' or 'default' in your working directory, so don't worry about this edge case.) If you do specify an existing file, the path/file will be resolved from the directory where you're calling Mint (the 'working directory'). To use Mint this way (and I don't see this as more than a temporary solution) you'll probably want to call Mint from within your source's directory. Alternatively, you can use [`Dir.chdir`][Dir::chdir method] for the same effect.
80
80
 
@@ -137,13 +137,13 @@ Templates are rendered in the context of the document they are "about", so Mint
137
137
 
138
138
  In Mint layouts, Ruby calls are sparse but necessary.
139
139
 
140
- If you're designing a layout, you need to indicate where Mint should place your content. For that simple reason, raw Html files cannot be layouts. Instead, if you want to use Html templates, you should use the Erb format. These files are essentially Html with the possibility for Ruby calls. You can even use the .html extension for your files. Just code the dynamic portion using Erb syntax.
140
+ If you're designing a layout, you need to indicate where Mint should place your content. For that simple reason, raw HTML files cannot be layouts. Instead, if you want to use HTML templates, you should use the ERB format. These files are essentially HTML with the possibility for Ruby calls. You can even use the .html extension for your files. Just code the dynamic portion using ERB syntax.
141
141
 
142
142
  Inside your template, use the `content` method to place your source's content.
143
143
 
144
144
  You will want to point to your document's stylesheet (via a relative URL) from within your layout, usually in the `<head/>` element. Use the `stylesheet` method.
145
145
 
146
- So if you're writing your layout using Erb, the template might look like this:
146
+ So if you're writing your layout using ERB, the template might look like this:
147
147
 
148
148
  <!doctype html>
149
149
  <html>
@@ -170,13 +170,13 @@ The same layout in Haml would be:
170
170
 
171
171
  ### Style your content ###
172
172
 
173
- You can build stylesheets using [Css][], [Sass/Scss][] or [Less][]. They will
173
+ You can build stylesheets using [CSS][], [SASS/SCSS][] or [Less][]. They will
174
174
  always be compiled. They will only be copied, though, if you specify a style
175
175
  destination.
176
176
 
177
177
  [Tilt templates]: http://github.com/rtomayko/tilt/blob/master/TEMPLATES.md "A listing of all templates supported by Tilt."
178
- [Css]: http://en.wikipedia.org/wiki/Cascading_Style_Sheets
179
- [Sass/Scss]: http://sass-lang.com/
178
+ [CSS]: http://en.wikipedia.org/wiki/Cascading_Style_Sheets
179
+ [SASS/SCSS]: http://sass-lang.com/
180
180
  [Less]: http://lesscss.org/
181
181
 
182
182
  Mint comes preloaded with several styles and layouts.
@@ -212,8 +212,8 @@ The default Mint path (in order) is:
212
212
 
213
213
  Templates should be in a directory named templates. Inside this directory, there should be a subdirectory for each template:
214
214
 
215
- - `${MINT_PATH}/templates/normal/style.sass`
216
- - `${MINT_PATH}/templates/normal/layout.haml`
215
+ - `MINT_PATH/templates/normal/style.sass`
216
+ - `MINT_PATH/templates/normal/layout.haml`
217
217
 
218
218
  Normally a style will go best with its layout complement. However, layouts and styles can be mixed and matched at your discretion. This is especially true where you are primarily customizing DOM elements with your stylesheet instead of targeting specific IDs or classes you're expecting to find. (In other words, this works best when your stylesheet focuses on modifying typography and not page layout.)
219
219
 
@@ -339,7 +339,7 @@ This section documents features that do not yet exist, but that I would like to
339
339
 
340
340
  ### Composed styles ###
341
341
 
342
- Not everyone wants to code an entire stylesheet every time he wants a new look. In fact, the most common use case for stylesheets is probably tweaking typography. For this reason (and to make this tool as accessible as possible), I want to implement a feature where you can select one stylesheet as a base and implement tweaks on top of that file, using a Yaml-based DSL. Of course Css makes this easy enough, but I want to implement this feature in such a way that it is easy and intuitive for everyone.
342
+ Not everyone wants to code an entire stylesheet every time he wants a new look. In fact, the most common use case for stylesheets is probably tweaking typography. For this reason (and to make this tool as accessible as possible), I want to implement a feature where you can select one stylesheet as a base and implement tweaks on top of that file, using a Yaml-based DSL. Of course CSS makes this easy enough, but I want to implement this feature in such a way that it is easy and intuitive for everyone.
343
343
 
344
344
  ### Packages ###
345
345
 
@@ -4,15 +4,27 @@ require 'optparse'
4
4
 
5
5
  module Mint
6
6
  module CommandLine
7
- # A map of all options that mint allows by default. Mint will
7
+ # Commandline-related helper methods
8
+
9
+ # Returns a map of all options that mint allows by default. Mint will
8
10
  # consume these arguments, with optional parameters, from
9
11
  # the commandline. (All other arguments are taken to be
10
12
  # filenames.)
13
+ #
14
+ # @return [Hash] a structured set of options that the commandline
15
+ # executable accepts
11
16
  def self.options
12
17
  options_file = "../../../#{Mint.files[:syntax]}"
13
18
  YAML.load_file File.expand_path(options_file, __FILE__)
14
19
  end
15
20
 
21
+ # Yields each commandline option specified by options_metadata as
22
+ # a key/value pair to a block. If the option does not take a param, the value
23
+ # will be specified as true.
24
+ #
25
+ # @param [Hash, #[]] options_metadata a structured set of options that the executable
26
+ # can use to parse commandline configuration options
27
+ # @return [OptionParser] an object that will parse ARGV when called
16
28
  def self.parser(options_metadata=Mint::CommandLine.options)
17
29
  optparse = OptionParser.new do |opts|
18
30
  opts.banner = 'Usage: mint [command] files [options]'
@@ -37,6 +49,13 @@ module Mint
37
49
  end
38
50
  end
39
51
 
52
+ # Returns a hash of all active options specified by file (for all scopes).
53
+ # That is, if you specify file as 'config.yaml', this will return the aggregate
54
+ # of all config.yaml-specified options in the Mint path, where more local
55
+ # members of the path take precedence over more global ones.
56
+ #
57
+ # @param [String] file a filename pointing to a Mint configuration file
58
+ # @return [Hash] a structured set of configuration options
40
59
  def self.configuration(file=Mint.files[:config])
41
60
  return nil unless file
42
61
  config_file = Pathname.new file
@@ -53,29 +72,49 @@ module Mint
53
72
  Helpers.symbolize_keys configuration
54
73
  end
55
74
 
75
+ # Returns all configuration options (as specified by the aggregate
76
+ # of all config files), along with opts, where opts take precedence.
77
+ #
78
+ # @param [Hash] additional options to add to the current configuration
79
+ # @return [Hash] a structured set of configuration options with opts
80
+ # overriding any options from config files
56
81
  def self.configuration_with(opts)
57
82
  configuration.merge opts
58
83
  end
59
84
 
85
+ # Mint built-in commands
86
+
87
+ # Prints a help banner
88
+ #
89
+ # @param [String, #to_s] message a message to output
90
+ # @return [void]
60
91
  def self.help(message)
61
92
  puts message
62
93
  end
63
94
 
64
- # Install the listed file to the scope listed, using
65
- # local as the default scope.
66
- def self.install(file, commandline_options)
95
+ # @param [File] file the file to install to the appropriate Mint directory
96
+ # @param [Hash] commandline_options a structured set of options, including
97
+ # a scope label that the method will use to choose the appropriate
98
+ # installation directory
99
+ # @return [void]
100
+ def self.install(file, commandline_options={})
67
101
  commandline_options[:local] = true
68
102
  scope = [:global, :user, :local].
69
103
  select {|e| commandline_options[e] }.
70
104
  first
71
105
 
72
- directory = path_for_scope(scope)
106
+ directory = Mint.path_for_scope(scope)
73
107
  FileUtils.copy file, directory
74
108
  end
75
109
 
76
- # If we get the edit command, will retrieve appropriate file
77
- # (probably a Mint template) and shell out that file to
78
- # the user's favorite editor.
110
+ # Retrieve named template file (probably a built-in or installed
111
+ # template) and shell out that file to the user's favorite editor.
112
+ #
113
+ # @param [String] name the name of a layout or style to edit
114
+ # @param [Hash] commandline_options a structured set of options, including
115
+ # a layout or style flag that the method will use to choose the appropriate
116
+ # file to edit
117
+ # @return [void]
79
118
  def self.edit(name, commandline_options)
80
119
  layout = commandline_options[:layout]
81
120
  style = commandline_options[:style]
@@ -94,6 +133,13 @@ module Mint
94
133
  system "#{editor} #{file}"
95
134
  end
96
135
 
136
+ # Updates configuration options persistently in the appropriate scope,
137
+ # which defaults to local.
138
+ #
139
+ # @param [Hash] opts a structured set of options to set on Mint at the specified
140
+ # scope
141
+ # @param [Symbol] scope the scope at which to apply the set of options
142
+ # @return [void]
97
143
  def self.configure(opts, scope=:local)
98
144
  config_directory = Mint.path_for_scope(scope, true)
99
145
  config_file = config_directory + Mint.files[:config]
@@ -101,8 +147,15 @@ module Mint
101
147
  Helpers.update_yaml opts, config_file
102
148
  end
103
149
 
104
- # Try to set a config option (at the specified scope) per
150
+ # Tries to set a config option (at the specified scope) per
105
151
  # the user's command.
152
+ #
153
+ # @param key the key to set
154
+ # @param value the value to set key to
155
+ # @param [Hash, #[]] commandline_options a structured set of options, including
156
+ # a scope label that the method will use to choose the appropriate
157
+ # scope
158
+ # @return [void]
106
159
  def self.set(key, value, commandline_options)
107
160
  commandline_options[:local] = true
108
161
  scope = [:global, :user, :local].
@@ -112,18 +165,25 @@ module Mint
112
165
  configure({ key => value }, scope)
113
166
  end
114
167
 
115
- # Display all active configurations, where local
168
+ # Displays the sum of all active configurations, where local
116
169
  # configurations override global ones.
170
+ #
171
+ # @return [void]
117
172
  def self.config
118
173
  puts YAML.dump(configuration)
119
174
  end
120
175
 
121
176
  # Renders and writes to file all resources described by a document.
122
- # Specifically: it renders itself (inside of its own layout) and then
123
- # renders its style. This method will overwrite any existing content
124
- # in a document's destination files. The `render_style` option
125
- # provides an easy way to stop Mint from rendering a style, even
126
- # if the document's style is not nil.
177
+ # Specifically: it publishes a document, using the document's accessors
178
+ # to determine file placement and naming, and then renders its style.
179
+ # This method will overwrite any existing content in a document's destination
180
+ # files. The `render_style` option provides an easy way to stop Mint from
181
+ # rendering a style, even if the document's style is not nil.
182
+ #
183
+ # @param [Array, #each] files a group of filenames
184
+ # @param [Hash, #[]] commandline_options a structured set of configuration options
185
+ # that will guide Mint.publish!
186
+ # @return [void]
127
187
  def self.mint(files, commandline_options)
128
188
  documents = []
129
189
  options = configuration_with commandline_options
@@ -140,4 +200,3 @@ module Mint
140
200
  end
141
201
  end
142
202
  end
143
-
@@ -4,8 +4,15 @@ module Mint
4
4
  'container'
5
5
  end
6
6
 
7
- # Mappings from "DSL" to actual CSS. This is not yet implemented, but
8
- # the plan is to translate this into something like:
7
+ # Maps a "DSL" onto actual CSS. This is not yet implemented, but
8
+ # the plan is to translate this ...
9
+ #
10
+ # ---
11
+ # Font: Helvetica
12
+ # Margin: 1 in
13
+ # Line spacing: 1.25
14
+ #
15
+ # ... into something like:
9
16
  #
10
17
  # #container {
11
18
  # font: (value specified and cleaned up)
@@ -4,24 +4,26 @@ require 'mint/style'
4
4
 
5
5
  module Mint
6
6
  class Document < Resource
7
- # The following provide reader/accessor methods for the objects's
8
- # important attributes. Each implicit reader is paired with an
9
- # explicit assignment method that processes a variety of input to a
10
- # standardized state.
11
-
12
- # When you set content, you are giving the document a renderer based
13
- # on the content file and are processing the templated content into
14
- # Html, which you can then access using via the content reader.
15
- attr_reader :content
7
+ # Implicit readers are paired with explicit accessors. This
8
+ # allows for processing variables before storing them.
9
+ attr_reader :content, :layout, :style
10
+
11
+ # Passes content through a renderer before assigning it to be
12
+ # the Document's content
13
+ #
14
+ # @param [File, #read, #basename] content the content to be rendered
15
+ # from a templating language into HTML
16
+ # @return [void]
16
17
  def content=(content)
17
18
  @renderer = Mint.renderer content
18
19
  @content = @renderer.render
19
20
  end
20
21
 
21
- # The explicit assignment method allows you to pass the document an existing
22
- # layout or the name of a layout template in the Mint path or an
23
- # existing layout file.
24
- attr_reader :layout
22
+ # Sets layout to an existing Layout object or looks it up by name
23
+ #
24
+ # @param [String, Layout, #render] layout a Layout object or name
25
+ # of a layout to be looked up
26
+ # @return [void]
25
27
  def layout=(layout)
26
28
  @layout =
27
29
  if layout.respond_to? :render
@@ -34,10 +36,11 @@ module Mint
34
36
  abort "Template '#{layout}' does not exist."
35
37
  end
36
38
 
37
- # The explicit assignment method allows you to pass the document an existing
38
- # style or the name of a style template in the Mint path or an
39
- # existing style file.
40
- attr_reader :style
39
+ # Sets layout to an existing Style object or looks it up by name
40
+ #
41
+ # @param [String, Style, #render] layout a Layout object or name
42
+ # of a layout to be looked up
43
+ # @return [void]
41
44
  def style=(style)
42
45
  @style =
43
46
  if style.respond_to? :render
@@ -50,23 +53,35 @@ module Mint
50
53
  abort "Template '#{style}' does not exist."
51
54
  end
52
55
 
56
+ # Explanation of style_destination:
57
+ #
53
58
  # I'm going to maintain a document's official style_destination
54
59
  # outside of its style object. If a document has no
55
60
  # style_destination defined when it needs one, the document will
56
- # use the style's source directory. This happens lazily via
57
- # virtual attributes like #style_destination_file, etc.
58
- # This eliminates edge cases (like styles we don't want to move
59
- # anywhere) nicely and lets us maintain document-specific information
60
- # separately. (Without this separation, funky things happen when
61
+ # use the original style's source directory.
62
+ #
63
+ # This decision eliminates edge cases, including the case where
64
+ # we want to generate, but not move, a document's style. It also
65
+ # lets us keep style information separate from document-specific
66
+ # information. (Without this separation, funky things happen when
61
67
  # you assign a new style template to an existing document -- if
62
68
  # you had specified a custom style_destination before changing
63
- # the template, that custom destination would be overridden.
64
-
69
+ # the template, that custom destination would be overridden.)
70
+ #
71
+ # The style_destination attribute is lazy. It's exposed via
72
+ # virtual attributes like #style_destination_file.
65
73
  attr_reader :style_destination
74
+ #
75
+ # @param [String] style_destination the subdirectory into
76
+ # which styles will be rendered or copied
77
+ # @return [void]
66
78
  def style_destination=(style_destination)
67
79
  @style_destination = style_destination
68
80
  end
69
81
 
82
+ # Exposes style_destination as a Pathname object.
83
+ #
84
+ # @return [Pathname]
70
85
  def style_destination_file_path
71
86
  if style_destination
72
87
  path = Pathname.new style_destination
@@ -78,18 +93,31 @@ module Mint
78
93
  end
79
94
  end
80
95
 
96
+ # Exposes style_destination as a String.
97
+ #
98
+ # @return [String]
81
99
  def style_destination_file
82
100
  style_destination_file_path.to_s
83
101
  end
84
102
 
103
+ # Exposes style_destination directory as a Pathname object.
104
+ #
105
+ # @return [Pathname]
85
106
  def style_destination_directory_path
86
107
  style_destination_file_path.dirname
87
108
  end
88
109
 
110
+ # Exposes style_destination directory as a String.
111
+ #
112
+ # @return [String]
89
113
  def style_destination_directory
90
114
  style_destination_directory_path.to_s
91
115
  end
92
116
 
117
+ # Overrides layout and style settings with named template.
118
+ #
119
+ # @param [String] template the name of the template to set as
120
+ # layout and string
93
121
  def template=(template)
94
122
  if template
95
123
  self.layout = template
@@ -97,6 +125,9 @@ module Mint
97
125
  end
98
126
  end
99
127
 
128
+ # Creates a new Mint Document object. Can be block initialized.
129
+ # Accepts source and options. Block initialization occurs after
130
+ # all defaults are set, so not all options must be specified.
100
131
  def initialize(source, opts={})
101
132
  options = Mint.default_options.merge opts
102
133
 
@@ -120,20 +151,20 @@ module Mint
120
151
  yield self if block_given?
121
152
  end
122
153
 
123
- # Render content in the context of layout
154
+ # Renders content in the context of layout and returns as a String.
124
155
  def render(args={})
125
156
  layout.render self, args
126
157
  end
127
158
 
128
- # Write all rendered content where a) possible, b) required,
129
- # and c) specified
159
+ # Writes all rendered content where a) possible, b) required,
160
+ # and c) specified. Outputs to specified file.
130
161
  def publish!(render_style=true)
131
162
  FileUtils.mkdir_p self.destination_directory
132
163
  File.open(self.destination_file, 'w+') do |f|
133
164
  f << self.render
134
165
  end
135
166
 
136
- # Only render style if a) it's specified by the options path and
167
+ # Only renders style if a) it's specified by the options path and
137
168
  # b) it actually needs rendering (i.e., it's in template form and
138
169
  # not raw, browser-parseable CSS) or it if it doesn't need
139
170
  # rendering but there is an explicit style_destination.
@@ -1,3 +1,5 @@
1
1
  module Mint
2
+ # Indicates that a named template is not located anywhere
3
+ # in the Mint path.
2
4
  class TemplateNotFoundException < Exception; end
3
5
  end
@@ -3,6 +3,11 @@ require 'yaml'
3
3
 
4
4
  module Mint
5
5
  module Helpers
6
+ # Transforms a String into a URL-ready slug. Properly handles
7
+ # ampersands, non-alphanumeric characters, extra hyphens and spaces.
8
+ #
9
+ # @param [String, #to_s] obj an object to be turned into a slug
10
+ # @return [String] a URL-ready slug
6
11
  def self.slugize(obj)
7
12
  obj.to_s.downcase.
8
13
  gsub(/&/, 'and').
@@ -11,10 +16,18 @@ module Mint
11
16
  gsub(/[-]+/, '-')
12
17
  end
13
18
 
19
+ # Transforms a potentially hyphenated String into a symbol name.
20
+ #
21
+ # @param [String, #to_s] obj an object to be turned into a symbol name
22
+ # @return [Symbol] a symbol representation of obj
14
23
  def self.symbolize(obj)
15
24
  slugize(obj).gsub(/-/, '_').to_sym
16
25
  end
17
26
 
27
+ # Transforms a String or Pathname into a fully expanded Pathname.
28
+ #
29
+ # @param [String, Pathname] str_or_path a path to be expanded
30
+ # @return [Pathname] an expanded representation of str_or_path
18
31
  def self.pathize(str_or_path)
19
32
  case str_or_path
20
33
  when String
@@ -24,6 +37,10 @@ module Mint
24
37
  end.expand_path
25
38
  end
26
39
 
40
+ # Recursively transforms all keys in a Hash into Symbols.
41
+ #
42
+ # @param [Hash, #[]] map a potentially nested Hash containing symbolizable keys
43
+ # @return [Hash] a version of map where all keys are symbols
27
44
  def self.symbolize_keys(map)
28
45
  map.reduce(Hash.new) do |syms,(k,v)|
29
46
  syms[k.to_sym] =
@@ -39,13 +56,24 @@ module Mint
39
56
 
40
57
  # Returns the relative path to dir1 from dir2. If dir1 and dir2
41
58
  # have no directories in common besides /, will return the
42
- # absolute directory of dir1. Right now, assumes no symlinks
59
+ # absolute directory of dir1. Assumes no symlinks.
60
+ #
61
+ # @param [String, Pathname] dir1 the target directory
62
+ # @param [String, Pathname] dir2 the starting directory
63
+ # @return [Pathname] the relative path to dir1 from dir2, or an absolute
64
+ # path if they have no parent directories other than / in common
43
65
  def self.normalize_path(dir1, dir2)
44
66
  path1, path2 = [dir1, dir2].map {|d| pathize d }
45
67
  root1, root2 = [path1, path2].map {|p| p.each_filename.first }
46
68
  root1 == root2 ? path1.relative_path_from(path2) : path1
47
69
  end
48
70
 
71
+ # Reads Yaml options from file. Updates values with new_opts. Writes
72
+ # merged data back to the same file, overwriting previous data.
73
+ #
74
+ # @param [Hash, #[]] new_opts a set of options to add to the Yaml file
75
+ # @param [Pathname, #exist] file a file to read from and write to
76
+ # @return [void]
49
77
  def self.update_yaml(new_opts, file)
50
78
  curr_opts = file.exist? ? YAML.load_file(file) : {}
51
79
 
@@ -1,10 +1,12 @@
1
1
  require 'mint/resource'
2
2
 
3
3
  module Mint
4
- # Layout describes a resource whose type is `:layout`. Beyond its type,
5
- # it is a simple resource. However, its type helps decide which template
6
- # file to use when a template name is specified.
7
4
  class Layout < Resource
5
+ # Creates a new Layout object using a mandatory source file
6
+ # and optional configuration options.
7
+ #
8
+ # @param [String] source the absolute or relative file path
9
+ # @param [Hash, #[]] opts layout options
8
10
  def initialize(source, opts=Mint.default_options)
9
11
  super(source, opts)
10
12
  self.type = :layout
@@ -3,8 +3,6 @@ require 'fileutils'
3
3
  require 'yaml'
4
4
  require 'tilt'
5
5
 
6
- require 'mint/exceptions'
7
-
8
6
  module Mint
9
7
  # Assume that someone using an Html template has formatted it
10
8
  # in Erb and that a Css stylesheet will pass untouched through
@@ -12,14 +10,18 @@ module Mint
12
10
  Tilt.register Tilt::ERBTemplate, :html
13
11
  Tilt.register Tilt::ScssTemplate, :css
14
12
 
13
+ # @return [String] the Mint root path name
15
14
  def self.root
16
15
  (Pathname.new(__FILE__).realpath.dirname + '../..').to_s
17
16
  end
18
17
 
19
- # Return the an array with the Mint template path. Will first look
18
+ # Returns an array with the Mint template path. Will first look
20
19
  # for MINT_PATH environment variable. Otherwise will use smart defaults.
21
20
  # Either way, earlier/higher paths take precedence. And is considered to
22
21
  # be the directory for "local" config options, templates, etc.
22
+ #
23
+ # @param [Boolean] as_path if as_path is true, will return Pathname objects
24
+ # @return [String] the Mint path as a String or Pathname
23
25
  def self.path(as_path=false)
24
26
  mint_path = ENV['MINT_PATH'] ||
25
27
  "#{Dir.getwd}/.mint:~/.mint:#{Mint.root}"
@@ -27,11 +29,16 @@ module Mint
27
29
  as_path ? paths.map {|p| Pathname.new(p).expand_path } : paths
28
30
  end
29
31
 
32
+ # Returns the part of Mint.path relevant to scope.
30
33
  # I want to refactor this so that Mint.path is always a Hash...
31
34
  # should take care of this in the Mint.path=() method.
32
35
  # Right now, this is a hack. It assumes a sane MINT_PATH, where the
33
36
  # first entry is most local, the second is user-level,
34
37
  # and the last entry is most global.
38
+ #
39
+ # @param [Symbol] scope the scope we want to find the path for
40
+ # @param [Boolean] as_path if as_path is true, will return Pathname object
41
+ # @return [String] the Mint path for +scope+ as a String or Pathname
35
42
  def self.path_for_scope(scope=:local, as_path=false)
36
43
  case Mint.path
37
44
  when Array
@@ -44,7 +51,7 @@ module Mint
44
51
  end
45
52
  end
46
53
 
47
- # Returns a hash with key Mint directories
54
+ # @return [Hash] key Mint directories
48
55
  def self.directories
49
56
  {
50
57
  templates: 'templates',
@@ -52,7 +59,7 @@ module Mint
52
59
  }
53
60
  end
54
61
 
55
- # Returns a hash with key Mint files
62
+ # @return [Hash] key Mint files
56
63
  def self.files
57
64
  {
58
65
  syntax: directories[:config] + '/syntax.yaml',
@@ -60,6 +67,7 @@ module Mint
60
67
  }
61
68
  end
62
69
 
70
+ # @return [Hash] last-resort options for creating Mint documents.
63
71
  def self.default_options
64
72
  {
65
73
  # Do not set default `template`--will override style and
@@ -71,19 +79,18 @@ module Mint
71
79
  }
72
80
  end
73
81
 
74
- # Returns a list of all file extensions that Tilt will render
82
+ # @return [Array] all file extensions that Tilt will render
75
83
  def self.formats
76
84
  Tilt.mappings.keys
77
85
  end
78
86
 
79
- # Registered Css formats, for source -> destination
80
- # name guessing/conversion only.
87
+ # @return [Array] CSS formats, for source -> destination
88
+ # name guessing/conversion only.
81
89
  def self.css_formats
82
- css_formats = ['css', 'sass', 'scss', 'less']
90
+ ['css', 'sass', 'scss', 'less']
83
91
  end
84
92
 
85
- # Lists the full path for each known template in the
86
- # Mint path
93
+ # @return [Array] the full path for each known template in the Mint path
87
94
  def self.templates
88
95
  templates_dir = Mint.directories[:templates]
89
96
 
@@ -104,19 +111,29 @@ module Mint
104
111
  # referring to the file ~/.mint/templates/normal/layout.erb.
105
112
  # Adding :style as a second argument returns
106
113
  # ~/.mint/templates/normal/style.css.
114
+ #
115
+ # @param [String, File, #to_s] name_or_file a name or template file
116
+ # to look up
117
+ # @param [Symbol] type the resource type to look up
118
+ # @return [File] the named, typed template file
107
119
  def self.lookup_template(name_or_file, type=:layout)
108
120
  name = name_or_file.to_s
109
121
  File.exist?(name) ? name : find_template(name, type)
110
122
  end
111
123
 
112
124
  # Finds a template named `name` in the Mint path. If `type` is :layout,
113
- # will look for `${MINT_PATH}/templates/layout.*`. If it is :style, will
114
- # look for `${MINT_PATH}/templates/template_name/style.*`. Mint assumes
125
+ # will look for `MINT_PATH/templates/layout.*`. If it is :style, will
126
+ # look for `MINT_PATH/templates/template_name/style.*`. Mint assumes
115
127
  # that a named template will hold only one layout and one style template.
116
128
  # It does not know how to decide between style.css and style.less, for
117
129
  # example. For predictable results, only include one template file
118
130
  # called `layout.*` in the `template_name` directory. Returns nil if
119
131
  # it cannot find a template.
132
+ #
133
+ # @param [String, #to_s] name the name of a template to find
134
+ # @param [Symbol] type the resource type to find
135
+ #
136
+ # @return [File] the named, typed template file
120
137
  def self.find_template(name, type)
121
138
  templates_dir = Mint.directories[:templates]
122
139
 
@@ -131,8 +148,11 @@ module Mint
131
148
  template
132
149
  end
133
150
 
134
- # A non-rigourous check to see if the file is somewhere on the
151
+ # Checks (non-rigorously) to see if the file is somewhere on the
135
152
  # MINT_PATH
153
+ #
154
+ # @param [String, File, #to_s] file the file to look up
155
+ # @return [Boolean] true if template file is found in Mint path
136
156
  def self.template?(file)
137
157
  paths = Mint.path.map {|f| File.expand_path f }
138
158
  file_path = Pathname.new(file)
@@ -142,6 +162,9 @@ module Mint
142
162
 
143
163
  # Guesses an appropriate name for the resource output file based on
144
164
  # its source file's base name
165
+ #
166
+ # @param [String] name source file name
167
+ # @return [String] probably output file name
145
168
  def self.guess_name_from(name)
146
169
  name = Pathname(name).basename if name
147
170
  css = Mint.css_formats.join '|'
@@ -152,10 +175,16 @@ module Mint
152
175
 
153
176
  # Transforms a path into a template that will render the file specified
154
177
  # at that path
178
+ #
179
+ # @param [Path, File, String, #to_s] path the file to render
155
180
  def self.renderer(path)
156
181
  Tilt.new path.to_s, :smart => true, :ugly => true
157
182
  end
158
183
 
184
+ # Publishes a Document object according to its internal specifications.
185
+ #
186
+ # @param [Document] document a Mint document
187
+ # @return [void]
159
188
  def self.publish!(document)
160
189
  document.publish!
161
190
  end
@@ -1,10 +1,12 @@
1
1
  require 'mint/resource'
2
2
 
3
3
  module Mint
4
- # Style describes a resource whose type is `:style`. Beyond its type,
5
- # it is a simple resource. However, its type helps decide which template
6
- # file to use when a template name is specified.
7
4
  class Style < Resource
5
+ # Creates a new Layout object using a mandatory source file
6
+ # and optional configuration options.
7
+ #
8
+ # @param [String] source the absolute or relative file path
9
+ # @param [Hash, #[]] opts style options
8
10
  def initialize(source, opts=Mint.default_options)
9
11
  super(source, opts)
10
12
  self.type = :style
@@ -12,8 +14,8 @@ module Mint
12
14
  # We want to render final stylesheet to the /css subdirectory if
13
15
  # an output directory is not specified and we are dealing with
14
16
  # a named template (not a local file). If we don't do this, the rendered
15
- # Css file might be picked up next time we look for a named template
16
- # in this directory, and the (correct) Sass file won't be picked up.
17
+ # CSS file might be picked up next time we look for a named template
18
+ # in this directory, and the (correct) SASS file won't be picked up.
17
19
  # However, if a destination directory is already specified, we
18
20
  # leave it alone.
19
21
  if Mint.template?(self.source_directory) and rendered?
@@ -21,6 +23,17 @@ module Mint
21
23
  end
22
24
  end
23
25
 
26
+ # Determines whether a Style object is supposed to be rendered.
27
+ #
28
+ # @return [Boolean] whether or not style should be rendered
29
+ def rendered?
30
+ source_file_path.extname !~ /\.css$/
31
+ end
32
+
33
+ # Renders a Style object if necessary. Otherwise, returns the contents
34
+ # of its source file.
35
+ #
36
+ # @return [String] a rendered stylesheet
24
37
  def render
25
38
  if rendered?
26
39
  super
@@ -28,9 +41,5 @@ module Mint
28
41
  File.read source
29
42
  end
30
43
  end
31
-
32
- def rendered?
33
- source_file_path.extname !~ /\.css$/
34
- end
35
44
  end
36
45
  end
@@ -1,3 +1,3 @@
1
1
  module Mint
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-10 00:00:00.000000000Z
12
+ date: 2011-08-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
16
- requirement: &70148467851220 !ruby/object:Gem::Requirement
16
+ requirement: &70150881334580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70148467851220
24
+ version_requirements: *70150881334580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdiscount
27
- requirement: &70148467850480 !ruby/object:Gem::Requirement
27
+ requirement: &70150881336760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70148467850480
35
+ version_requirements: *70150881336760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: erubis
38
- requirement: &70148467849680 !ruby/object:Gem::Requirement
38
+ requirement: &70150881338620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70148467849680
46
+ version_requirements: *70150881338620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: haml
49
- requirement: &70148467848720 !ruby/object:Gem::Requirement
49
+ requirement: &70150881340960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70148467848720
57
+ version_requirements: *70150881340960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sass
60
- requirement: &70148467847980 !ruby/object:Gem::Requirement
60
+ requirement: &70150881345260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70148467847980
68
+ version_requirements: *70150881345260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdiscount
71
- requirement: &70148467847080 !ruby/object:Gem::Requirement
71
+ requirement: &70150892156560 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70148467847080
79
+ version_requirements: *70150892156560
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: liquid
82
- requirement: &70148467846440 !ruby/object:Gem::Requirement
82
+ requirement: &70150892061900 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70148467846440
90
+ version_requirements: *70150892061900
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: less
93
- requirement: &70148467845440 !ruby/object:Gem::Requirement
93
+ requirement: &70150892061440 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70148467845440
101
+ version_requirements: *70150892061440
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: radius
104
- requirement: &70148467825500 !ruby/object:Gem::Requirement
104
+ requirement: &70150892060900 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70148467825500
112
+ version_requirements: *70150892060900
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: markaby
115
- requirement: &70148467824800 !ruby/object:Gem::Requirement
115
+ requirement: &70150892060360 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *70148467824800
123
+ version_requirements: *70150892060360
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rspec
126
- requirement: &70148467823900 !ruby/object:Gem::Requirement
126
+ requirement: &70150892059940 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70148467823900
134
+ version_requirements: *70150892059940
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: cucumber
137
- requirement: &70148467823220 !ruby/object:Gem::Requirement
137
+ requirement: &70150892059400 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70148467823220
145
+ version_requirements: *70150892059400
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: aruba
148
- requirement: &70148467822400 !ruby/object:Gem::Requirement
148
+ requirement: &70150892058860 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *70148467822400
156
+ version_requirements: *70150892058860
157
157
  description:
158
158
  email: david@allthingsprogress.com
159
159
  executables: