Class: Spriteful::Stylesheet
- Inherits:
-
Object
- Object
- Spriteful::Stylesheet
- Defined in:
- lib/spriteful/stylesheet.rb
Overview
Public: class responsible for putting together the CSS code to use a specific sprite.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Public: returns the format used to render the Stylesheet.
-
#path ⇒ Object
readonly
Public: returns the path where the Stylesheet should be stored.
-
#sprite ⇒ Object
readonly
Public: returns the ‘Sprite’ of this Stylesheet.
-
#template_path ⇒ Object
readonly
Public: returns the custom template path.
Class Method Summary collapse
-
.expand_template_path(format) ⇒ Object
Internal: Expands the path to the default stylesheet for the given format.
-
.read_template(format) ⇒ Object
Internal: Reads the default template Stylesheet for the given format.
Instance Method Summary collapse
-
#initialize(sprite, destination, options = {}) ⇒ Stylesheet
constructor
Public: Initialize a Stylesheet.
-
#name ⇒ Object
Public: returns this Stylesheet name, based on the Sprite name and the current format.
-
#render ⇒ Object
Public: renders the CSS code for this Stylesheet.
Constructor Details
#initialize(sprite, destination, options = {}) ⇒ Stylesheet
Public: Initialize a Stylesheet
sprite - a ‘Sprite’ object to create the Stylesheet. destination - the directory where the Stylesheet will be created. options - additional Hash of options.
:format - the Stylesheet format.
:mixin - Use mixins instead of Placeholder selector in the SCSS format.
:rails - A flag to generate Asset Pipeline compatible Stylesheets.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spriteful/stylesheet.rb', line 27 def initialize(sprite, destination, = {}) @sprite = sprite @options = @destination = destination @format = [:format] @rails = !![:rails] @template_path = [:template] || self.class.(@format) @path = File.join(@destination, name) end |
Instance Attribute Details
#format ⇒ Object (readonly)
Public: returns the format used to render the Stylesheet.
8 9 10 |
# File 'lib/spriteful/stylesheet.rb', line 8 def format @format end |
#path ⇒ Object (readonly)
Public: returns the path where the Stylesheet should be stored.
14 15 16 |
# File 'lib/spriteful/stylesheet.rb', line 14 def path @path end |
#sprite ⇒ Object (readonly)
Public: returns the ‘Sprite’ of this Stylesheet.
11 12 13 |
# File 'lib/spriteful/stylesheet.rb', line 11 def sprite @sprite end |
#template_path ⇒ Object (readonly)
Public: returns the custom template path.
17 18 19 |
# File 'lib/spriteful/stylesheet.rb', line 17 def template_path @template_path end |
Class Method Details
.expand_template_path(format) ⇒ Object
Internal: Expands the path to the default stylesheet for the given format.
Returns the path as a String.
69 70 71 |
# File 'lib/spriteful/stylesheet.rb', line 69 def self.(format) File.("../stylesheets/template.#{format}.erb", __FILE__) end |
.read_template(format) ⇒ Object
Internal: Reads the default template Stylesheet for the given format.
Returns a String.
61 62 63 64 |
# File 'lib/spriteful/stylesheet.rb', line 61 def self.read_template(format) path = (format) File.read(path) end |
Instance Method Details
#name ⇒ Object
Public: returns this Stylesheet name, based on the Sprite name and the current format.
Returns a String.
53 54 55 56 |
# File 'lib/spriteful/stylesheet.rb', line 53 def name extension = rails? ? rails_extension : format "#{sprite_name}.#{extension}" end |
#render ⇒ Object
Public: renders the CSS code for this Stylesheet. An ERB template will be used to process the code, based on the stylesheet format.
Returns the CSS code as a ‘String’.
44 45 46 47 |
# File 'lib/spriteful/stylesheet.rb', line 44 def render template = Template.new(@sprite, ) template.render(File.read(template_path)) end |