Class: Jquery::Generators::UiGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/generators/jquery/ui/ui_generator.rb

Instance Method Summary collapse

Methods inherited from Base

source_root

Instance Method Details

#copy_javascript_filesObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/jquery/ui/ui_generator.rb', line 23

def copy_javascript_files
  Dir.glob("#{unzip_path}/js/jquery-*.min.js").each do |js_file|
    source_file = expand_app_path(js_file)
    if js_file =~ /-ui-.+\.custom/ # jquery-ui-VERSION.custom.js
      copy_file source_file, 'public/javascripts/jquery-ui.js'
    else # jquery-VERSION.js
      copy_file source_file, 'public/javascripts/jquery.js'
    end
  end
end

#copy_stylesheet_filesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/jquery/ui/ui_generator.rb', line 34

def copy_stylesheet_files
  Dir.glob("#{unzip_path}/css/**/*").each do |css_file|
    source_file = expand_app_path(css_file)
    target_file = css_file.sub("#{unzip_path}/css", 'public/stylesheets')
    if File.directory? source_file
      empty_directory target_file
    elsif source_file =~ /\.png$/ # images/*.png
      copy_file source_file, target_file
    elsif source_file =~ /\.css$/ # jquery-ui-VERSION.custom.css
      copy_file source_file, target_file.sub(/-ui-.+\.css$/, '-ui.css')
    end
  end
end

#create_application_layout_fileObject



52
53
54
# File 'lib/generators/jquery/ui/ui_generator.rb', line 52

def create_application_layout_file
  copy_file 'application.html.erb', 'app/views/layouts/application.html.erb'
end

#create_initializer_fileObject



48
49
50
# File 'lib/generators/jquery/ui/ui_generator.rb', line 48

def create_initializer_file
  copy_file 'jquery.rb', 'config/initializers/jquery.rb'
end

#delete_tmp_filesObject



56
57
58
59
60
61
62
63
64
# File 'lib/generators/jquery/ui/ui_generator.rb', line 56

def delete_tmp_files
  in_root do
    if options[:clean]
      run "rm -rf #{app_tmp_path}", :verbose => false
    else
      run "rm -rf #{unzip_path}", :verbose => false
    end
  end
end

#fetch_jquery_ui_filesObject



10
11
12
13
14
15
16
# File 'lib/generators/jquery/ui/ui_generator.rb', line 10

def fetch_jquery_ui_files
  empty_directory app_tmp_path
  inside(app_tmp_path) do
    get "#{download_path}/#{zip_file}", zip_file unless File.exists? zip_file
    run "unzip #{zip_file} -d #{unzip_folder}", :verbose => false
  end
end

#fetch_rails_jquery_ujs_fileObject



18
19
20
# File 'lib/generators/jquery/ui/ui_generator.rb', line 18

def fetch_rails_jquery_ujs_file
  get 'http://github.com/rails/jquery-ujs/raw/master/src/rails.js', 'public/javascripts/rails.js'
end

#show_readmeObject



66
67
68
# File 'lib/generators/jquery/ui/ui_generator.rb', line 66

def show_readme
  readme 'README'
end