module StayClassyProcess

Public Instance Methods

add_classes_to_file( filename ) click to toggle source

Champ Kind - Slap some BBQ sauce on them elements and woo, woo, woo!!!!

# File lib/stay_classy/stay_classy_process.rb, line 76
def add_classes_to_file( filename )

        path = "#{ @view_directory }#{ filename }"
        temp_file = Tempfile.new( 'foo' )

        begin
          File.open( path, 'r' ) do |file|
            file.each_line do |line|
              temp_file.puts make_classy( line, @file_identifier )
            end
          end
          temp_file.close
          FileUtils.mv( temp_file.path, path )
        rescue Exception => e
                baxter( e )
        ensure
          temp_file.close
          temp_file.unlink
        end

end
Also aliased as: champ_kind
add_ids_to_file( filename ) click to toggle source

Brick Tamland - Invite the ids to the pants party

# File lib/stay_classy/stay_classy_process.rb, line 101
def add_ids_to_file( filename )
        path = "#{ @view_directory }#{ filename }"
        temp_file = Tempfile.new( 'foo' )

        begin
          File.open( path, 'r' ) do |file|
            file.each_line do |line|
              temp_file.puts show_me_your_id( line )
            end
          end
          temp_file.close
          FileUtils.mv( temp_file.path, path )
        rescue Exception => e
                baxter( e )
        ensure
          temp_file.close
          temp_file.unlink
        end
end
Also aliased as: brick_tamland
baxter( exception )
Alias for: error_notifier
brian_fantana( file )
Alias for: load_file
brick_tamland( filename )
Alias for: add_ids_to_file
champ_kind( filename )
Alias for: add_classes_to_file
error_notifier( exception ) click to toggle source

Really doesn’t need to be here. He just barks out errors

# File lib/stay_classy/stay_classy_process.rb, line 126
def error_notifier( exception )
        @errors << exception
end
Also aliased as: baxter
load_file( file ) click to toggle source

Brian Fantana - Get the bits of real panther so you know it’s good (it opens the file)

# File lib/stay_classy/stay_classy_process.rb, line 65
def load_file( file )
        begin
                @filename = file
        rescue Exception => e
                baxter( e )
        end
end
Also aliased as: brian_fantana
make_classy( line, file_identifier ) click to toggle source

THESE TWO ARE THE BRANS OF THIS OPERATION #############

# File lib/stay_classy/stay_classy_process.rb, line 134
def make_classy( line, file_identifier )
        # TODO: should add file name to end of class
        StayClassy::Builder::DEFAULT_CLASS_TAGS.each do |tag|
                if line.include?( "<#{ tag }" ) && !line.include?( "class=" )
                        line = line.gsub( "<#{ tag }", "<#{ tag } class=\"#{ @prefix }#{ tag }_#{ file_identifier }\"" )
                end
        end
        return line
end
process( stay_classy ) click to toggle source

Once you’ve built an instance of stay_classy, it’s time to hand it over to the channel 6 news team.

# File lib/stay_classy/stay_classy_process.rb, line 7
def process( stay_classy )

        # I don't know if you heard me counting but I can do over a thousand
        @id_counter = 0

        @prefix = stay_classy.instance_variable_get( :@prefix )
        view_dirs = stay_classy.instance_variable_get( :@view_directories )

        printf "\nDirectories to make classy with prefix #{ @prefix }: \n".colorize( :yellow )
        view_dirs.map { |vd| printf "#{ vd }\n" }

        # Send the right files to the news team...
        printf "\nFiles to make classy: \n".colorize( :yellow )
        view_dirs.each do |vd|
                Dir.foreach( vd ) do |file|
                        # Send each file in each file in the directory to each member of the news team
                        begin
                                @errors = []

                                if file.match( StayClassy::Builder::VIEW_FILE_TYPES_REGEX )

                                        printf "#{ file }\n"
                                        @view_directory = vd

                                        # Strip the underscore from partials and get a clean file name to add to the classes
                                        if file[0] == '_'
                                                @file_identifier = file[ 1..-1 ].gsub( '.html', '' ).gsub( '.erb', '' )
                                        else
                                                @file_identifier = file.gsub( '.html', '' ).gsub( '.erb', '' )
                                        end

                                        # Brian Fantana for Sex Pantherization. He gets @filename for the rest of the team.
                                        brian_fantana( file )

                                        # Champ Kind takes @filename for sex and chicken
                                        champ_kind( @filename )

                                        # Puts @filename in a toaster...fantastic
                                        brick_tamland( @filename )

                                end

                        rescue Exception => e

                                # Bark out those errors, Baxter. You know I don't speak Spanish.
        baxter( e )
        printf "#{ @errors }\n" if @errors.any?

                        end
        end
end

end
show_me_your_id( line ) click to toggle source
# File lib/stay_classy/stay_classy_process.rb, line 144
def show_me_your_id( line )
        StayClassy::Builder::DEFAULT_ID_TAGS.each do |tag|
                if line.include?( "<#{ tag }" ) && !line.include?( "id=" )
                        line = line.gsub( "<#{ tag }", "<#{ tag } id=\"#{ @prefix }#{ tag }_#{ @id_counter }\"" )
                        @id_counter += 1
                end
        end
        return line
end