Class: Rake::RailsPluginPackageTask

Inherits:
TaskLib
  • Object
show all
Defined in:
lib/rails_plugin_package_task.rb

Overview

RailsPluginPackageTask defines the “rails_plugin” task that recurses through your package_files, generates compliant index.html for each folder (that contains a file), and creates a directory structure that you can publish as a set for your plugin.

Noteworthy attributes:

package_dir

Directory to store the package. Default ‘pkg/rails_plugin’

package_dir

Files to include in the plugin.

extra_links

Links to put on every generated index page. Can be a hash, e.g. href="http://roxml.rubyforge.org">roxml.rubyforge.org”, an array of strings or a single string.

plugin_files

Files to be placed in the root folder of the plug-in, e.g. init.rb. All files that are in the root of package_dir will also be placed in the root of the plug-in.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, version = nil) {|_self| ... } ⇒ RailsPluginPackageTask

Create the “rails_plugin” task

Yields:

  • (_self)

Yield Parameters:



43
44
45
46
47
# File 'lib/rails_plugin_package_task.rb', line 43

def initialize(name=nil, version=nil)
  init(name, version)
  yield self if block_given?
  define unless name.nil?
end

Instance Attribute Details

Homepage for more information



38
39
40
# File 'lib/rails_plugin_package_task.rb', line 38

def extra_links
  @extra_links
end

#nameObject

Name of plug-in or application



28
29
30
# File 'lib/rails_plugin_package_task.rb', line 28

def name
  @name
end

#package_dirObject

Directory used to store the package files (default is ‘pkg/rails_plugin’).



32
33
34
# File 'lib/rails_plugin_package_task.rb', line 32

def package_dir
  @package_dir
end

#package_filesObject

Files to be stored in the package



34
35
36
# File 'lib/rails_plugin_package_task.rb', line 34

def package_files
  @package_files
end

#plugin_filesObject

Files to go into the root of the plug-in folder (e.g. init.rb)



36
37
38
# File 'lib/rails_plugin_package_task.rb', line 36

def plugin_files
  @plugin_files
end

#verboseObject

Verbose [true | false]



40
41
42
# File 'lib/rails_plugin_package_task.rb', line 40

def verbose
  @verbose
end

#versionObject

Version of plugin - distribution folder will be name_version



30
31
32
# File 'lib/rails_plugin_package_task.rb', line 30

def version
  @version
end

Instance Method Details

#defineObject

Define the rails_plugin task



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rails_plugin_package_task.rb', line 62

def define
  desc "Create Ruby on Rails plug-in package"
  task :rails_plugin do
    @dest = "#@package_dir/#{@name}_#{@version}"
    makedirs(@dest,:verbose=>false)
    @plugin_files.each do |fn|
      cp(fn, @dest,:verbose=>false)
      add_file(File.basename(fn))
    end
    
    @package_files.each do |fn|
      puts ". #{fn}" if verbose
      f = File.join(@dest, fn)
      fdir = File.dirname(f)
      unless File.exist?(fdir)
        mkdir_p(fdir,:verbose=>false)
        add_folder("#{fdir}/")
      end
      if File.directory?(fn)
        mkdir_p(f,:verbose=>false)
        add_folder("#{fn}/")
      else
        cp(fn, f, :verbose=>false)
        add_file(fn)
      end
    end
    
    generate_index_files()
  end
end

#generate_index_filesObject

Generate the index.html files



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rails_plugin_package_task.rb', line 94

def generate_index_files
  @folders.each do |folder, files|
    puts " + Creating #{@dest}/#{folder}/index.html" if @verbose
    File.open("#{@dest}/#{folder}/index.html", "w") do |index|
      title = "Rails Plug-in for #@name #@version"
      index.write("<html><head><title>#{title}</title></head>\n")
      index.write("<body>\n")
      index.write("<h2>#{title}</h2>\n")
      extra_links = create_extra_links()
      index.write("<p>#{extra_links}</p>\n") if extra_links          
      files.each { |fn|
        puts("  - Adding #{fn}") if @verbose
        index.write("&nbsp;&nbsp;<a href=\"#{fn}\">#{fn}</a><br/>\n")
      }
      index.write("<hr size=\"1\"/><p style=\"font-size: x-small\">Generated with RailsPluginPackageTask<p>")
      index.write("</body>\n")
      index.write("</html>\n")
    end
  end
end

#init(name, version) ⇒ Object

Initialize with defaults



50
51
52
53
54
55
56
57
58
59
# File 'lib/rails_plugin_package_task.rb', line 50

def init(name, version)
  @name = name
  @version = version
  @extra_links = nil
  @package_files = Rake::FileList.new
  @plugin_files = Rake::FileList.new
  @package_dir = 'pkg/rails_plugin'
  @folders = {}
  @verbose = false
end