class StayClassy::Builder
Constants
- DEFAULT_CLASS_TAGS
- DEFAULT_ID_TAGS
- VIEWS_DIR
StayClassy
will only look within the rails/app/views directory. Leave the rest to the channel 9 news team ########- VIEW_FILE_TYPES_REGEX
Public Class Methods
new( options )
click to toggle source
# File lib/stay_classy.rb, line 34 def initialize( options ) begin # Handle user-specified directories here if !options[:dirs].empty? directories = options[:dirs] @view_directories = [] directories.each do |dir| # Filter out the not so classy characters. No scotch or ribs for them. Banish them to a whale's vagina dir = dir.gsub( /[^0-9a-z_-]/i, '' ) # Build an array of valid directories, kind of like a shelf of leather-bound books. if valid_dir?( dir ) @view_directories << "#{ VIEWS_DIR }/#{ dir }" else printf "\n#{ VIEWS_DIR }/#{ dir } is not a valid directory. That's bush!\n".colorize( :red ) end end else @view_directories = get_view_directories end ######## Prefix for all classes/ids ######## options[:prefix] ? @prefix = set_prefix( options[:prefix].to_s ) : @prefix = 'classy_' if options[:tags] # TODO: Check if valid HTML tag ######## Handle tags passed in ######## end rescue Exception => e raise e end end
Public Instance Methods
get_view_directories()
click to toggle source
If no directories are specified, find every directory in the views folder recursively
# File lib/stay_classy.rb, line 78 def get_view_directories Dir.glob( "#{ VIEWS_DIR }**/*/" ).select { |f| File.directory? f } end
set_prefix( prefix )
click to toggle source
# File lib/stay_classy.rb, line 82 def set_prefix( prefix ) starter_string = prefix.gsub( /[^0-9a-z_-]/i, '' ) return "#{ starter_string }_" end
valid_dir?( directory )
click to toggle source
Sixty percent of the time, valid directories will return true every time
# File lib/stay_classy.rb, line 73 def valid_dir?( directory ) Dir.exists?( "#{ VIEWS_DIR }/#{ directory }" ) end