class ConvertToBootstrap3::Converter

Attributes

converter_url[RW]

Public Class Methods

new() click to toggle source
# File lib/convert_to_bootstrap3.rb, line 18
def initialize
  @converter_url = 'http://code.divshot.com/bootstrap3_upgrader/'
end

Public Instance Methods

convert_in_place(directory = "") click to toggle source
# File lib/convert_to_bootstrap3.rb, line 22
def convert_in_place(directory = "")
  directory << '**/*.html*'

  visit @converter_url

  all_files = Dir.glob(directory).reject { |file| File.directory? file }

  all_files.each { |file| convert_file_contents(file) }
end

Private Instance Methods

convert_file_contents(file) click to toggle source
# File lib/convert_to_bootstrap3.rb, line 34
def convert_file_contents(file)
  file_contents = File.read(file)

  fill_in 'source', with: file_contents
  click_button 'Convert This Code'

  all(:xpath, "//textarea[@id='result']").each do |a|
    result = fix_embedded_language_tags a.value
    File.open(file, 'w+') { |f| f.write(result) }
  end
end
fix_embedded_language_tags(string) click to toggle source
# File lib/convert_to_bootstrap3.rb, line 46
def fix_embedded_language_tags(string)
  fix_php_tags fix_ruby_tags string
end
fix_php_tags(string) click to toggle source
# File lib/convert_to_bootstrap3.rb, line 55
def fix_php_tags(string)
  string.gsub(/(<!--)\?(php)/, '<?php').gsub(/(<!--)\?/, '<?').gsub(/\?(-->)/, '?>')
end
fix_ruby_tags(string) click to toggle source
# File lib/convert_to_bootstrap3.rb, line 50
def fix_ruby_tags(string)
  string.gsub(/&lt;%=/, '<%=').gsub(/&lt;%#/, '<%#').gsub(/&lt;%-/, '<%-')
        .gsub(/&lt;%/, '<%').gsub(/=&gt;/, '=>').gsub(/%&gt;/, '%>')
end