Module: RTLit::Util
- Defined in:
- lib/rtlit/util.rb
Overview
Files and directories utilities for converting CSS-formatted files to RTL
Class Method Summary collapse
-
.process_directory(src, dest, ext = nil) ⇒ Object
Converts CSS-formatted files in a directory, optionally filtered by extension, to RTL.
-
.process_file(src, dest) ⇒ Object
Converts CSS-formatted file to RTL.
-
.process_file_or_directory(src, dest, ext = nil) ⇒ Object
Convert CSS-formatted file or directory containing such files, which can optionally be filtered by file extension.
Class Method Details
.process_directory(src, dest, ext = nil) ⇒ Object
Converts CSS-formatted files in a directory, optionally filtered by extension, to RTL.
Accepts source and destination directories and an optional file extension string
Exmaple:
process_directory('/tmp', '/tmp/rtl', 'less')
38 39 40 41 42 43 44 45 |
# File 'lib/rtlit/util.rb', line 38 def process_directory(src, dest, ext = nil) src_path = '%s/*.%s' % [File.(src), ext || '*'] dest_path = File. dest Dir.glob(src_path) do |file| dest_file = File.join(dest_path,File.basename(file)) process_file(file, dest_file) end end |
.process_file(src, dest) ⇒ Object
Converts CSS-formatted file to RTL.
Accepts source and destination file paths.
Example:
process_file('/path/to/file.css', '/path/to/file-rtl.css')
19 20 21 22 23 24 25 |
# File 'lib/rtlit/util.rb', line 19 def process_file(src, dest) puts 'Reading %s' % src css = File.open(src,'r'){ |f| f.read } rtl_css = RTLit::Converter.to_rtl css puts 'writing %s' % dest File.open(dest,'w'){ |f| f.write rtl_css } end |
.process_file_or_directory(src, dest, ext = nil) ⇒ Object
Convert CSS-formatted file or directory containing such files, which can optionally be filtered by file extension.
Accepts source and destination paths to file or directory to convert and an optional file extension string to filter by (in case source path is a directory)
Example:
process_file_or_directory('/some/path', '/some/dest', 'less') # process only .less files directory
process_file_or_directory('/some/file.css','/some/file-rtl.css')
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rtlit/util.rb', line 60 def process_file_or_directory(src, dest, ext = nil) raise 'Source not given' if src.nil? or not File.exists? src raise 'Destination not given' if dest.nil? or not File.exists? dest if File.directory? src process_directory(src, dest, ext) else process_file(src, dest) end end |