Class: WebifyRuby::Css
- Inherits:
-
Object
- Object
- WebifyRuby::Css
- Defined in:
- lib/webify_ruby/css.rb
Overview
Public: Css class of the module which is to calculate paths, generate code, and write to a file if explicitely called.
Examples
WebifyRuby::Css.new('name', 'example.ttf', :svg)
# => #<WebifyRuby::Css:0x007feec39a5df8>
Class Attribute Summary collapse
-
.link_to ⇒ Object
Returns the value of attribute link_to.
-
.relative_from ⇒ Object
Returns the value of attribute relative_from.
Instance Attribute Summary collapse
-
#css_file ⇒ Object
readonly
Internal: Returns the String filepath of the .css file that should be created.
-
#dir ⇒ Object
readonly
Internal: Returns the String directory path where a .css file should be created.
-
#filename ⇒ Object
readonly
Internal: Returns the String name of the file withotut extension.
-
#output ⇒ Object
readonly
Internal: Returns the Fixnum length of created file’s css content.
-
#result ⇒ Object
readonly
Public: Returns the String CSS code.
-
#url ⇒ Object
readonly
Internal: Returns the String prefix of the font url to use in CSS stylesheet.
Instance Method Summary collapse
-
#initialize(name, file, *has) ⇒ Css
constructor
Public: Initialize a CSS generation / distribution.
-
#write(dir) ⇒ Object
Internal: (Re-)Create a CSS file and write code there.
Constructor Details
#initialize(name, file, *has) ⇒ Css
Public: Initialize a CSS generation / distribution.
name - A String name that will be used to name a font and stylesheet file. file - A String name that will be used to link to the font files. has - A zero or more Symbol font types that a stylesheet will use.
Valid symbols are: :eot, :svg, :woff, :ttf.
Returns the String CSS stylesheet code.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/webify_ruby/css.rb', line 91 def initialize(name, file, *has) [name, file, has] @has = has @name = name @filename = File.basename(file, '.*') # :nocov: @url = (self.class.relative_from.nil? ? (self.class.link_to ? (self.class.link_to + '/' + File.basename(file)) : file) : (self.class.link_to ? (self.class.link_to + '/' + File.basename(file)) : file)).to_s[/.*(?=\..+$)/] # :nocov: make_css end |
Class Attribute Details
.link_to ⇒ Object
Returns the value of attribute link_to.
81 82 83 |
# File 'lib/webify_ruby/css.rb', line 81 def link_to @link_to end |
.relative_from ⇒ Object
Returns the value of attribute relative_from.
81 82 83 |
# File 'lib/webify_ruby/css.rb', line 81 def relative_from @relative_from end |
Instance Attribute Details
#css_file ⇒ Object (readonly)
Internal: Returns the String filepath of the .css file that should be created.
39 40 41 |
# File 'lib/webify_ruby/css.rb', line 39 def css_file @css_file end |
#dir ⇒ Object (readonly)
Internal: Returns the String directory path where a .css file should be created.
37 38 39 |
# File 'lib/webify_ruby/css.rb', line 37 def dir @dir end |
#filename ⇒ Object (readonly)
Internal: Returns the String name of the file withotut extension.
33 34 35 |
# File 'lib/webify_ruby/css.rb', line 33 def filename @filename end |
#output ⇒ Object (readonly)
Internal: Returns the Fixnum length of created file’s css content.
41 42 43 |
# File 'lib/webify_ruby/css.rb', line 41 def output @output end |
#result ⇒ Object (readonly)
Public: Returns the String CSS code.
31 32 33 |
# File 'lib/webify_ruby/css.rb', line 31 def result @result end |
#url ⇒ Object (readonly)
Internal: Returns the String prefix of the font url to use in CSS stylesheet.
35 36 37 |
# File 'lib/webify_ruby/css.rb', line 35 def url @url end |
Instance Method Details
#write(dir) ⇒ Object
Internal: (Re-)Create a CSS file and write code there.
dir - The String directory path to write CSS file to.
Returns the css file just written.
113 114 115 116 117 118 119 120 |
# File 'lib/webify_ruby/css.rb', line 113 def write(dir) @dir = FileUtils.mkdir_p dir @css_file = File.join(@dir, @filename + '.css') File.delete(@css_file) if File.exist?(@css_file) @output = File.open(@css_file, 'w') { |file| file.write(@result) } @css_file end |