class Rabbit::Task::Theme

Attributes

package_dir[RW]
pdf_dir[RW]
required_rabbit_version[RW]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/rabbit/task/theme.rb, line 34
def initialize
  @logger = Logger.default
  @theme = load_theme_configuration
  @spec = nil
  @package_dir = "pkg"
  @pdf_dir = "pdf"
  @required_rabbit_version = ">= 2.0.2"
  yield(self) if block_given?
  define
end

Public Instance Methods

spec() click to toggle source
# File lib/rabbit/task/theme.rb, line 45
def spec
  @spec ||= create_spec
end

Private Instance Methods

create_spec() click to toggle source
# File lib/rabbit/task/theme.rb, line 56
def create_spec
  readme_parser = READMEParser.new(@logger)
  readme_parser.parse

  Gem::Specification.new do |spec|
    spec.name = @theme.gem_name
    spec.version = @theme.version
    spec.homepage = homepage
    spec.authors = [@theme.author.name]
    spec.email = [@theme.author.email]
    spec.summary = readme_parser.title || "TODO"
    spec.description = readme_parser.description || "TODO"
    spec.licenses = @theme.licenses

    theme_conf_path = @theme.path
    spec.files = [theme_conf_path, "Rakefile"]
    spec.files += Dir.glob("{theme.rb,COPYING,GPL,README*}")
    spec.files += Dir.glob("data/**/*.{svg,png,jpg,jpeg,gif,eps,pdf}")
    spec.files += Dir.glob("locale/**/*.mo")
    spec.files += Dir.glob("po/*/*.po")
    theme_benchmark_locales.each do |locale|
      spec.files += [theme_benchmark_pdf_path(locale)]
    end

    spec.add_runtime_dependency("rabbit", @required_rabbit_version)
  end
end
define() click to toggle source
# File lib/rabbit/task/theme.rb, line 84
def define
  task :default => :run

  define_run_task
  define_gem_task
  define_pdf_task
  define_publish_task
end
define_gem_create_task() click to toggle source
# File lib/rabbit/task/theme.rb, line 105
def define_gem_create_task
  desc(_("Create gem: %{gem_path}") % {:gem_path => gem_path})
  task :gem => ["gem:validate", :pdf] do
    mkdir_p(@package_dir)
    GemBuilder.build(spec)
    mv(File.basename(spec.cache_file), gem_path)
  end
end
define_gem_task() click to toggle source
# File lib/rabbit/task/theme.rb, line 100
def define_gem_task
  define_gem_create_task
  define_gem_validate_task
end
define_gem_validate_task() click to toggle source
# File lib/rabbit/task/theme.rb, line 114
def define_gem_validate_task
  namespace :gem do
    task :validate do
      errors = []
      format = _("Write %{item} in %{where}: %{content}")
      data = {
        :where => Dir.glob("README*")[0],
      }
      [:summary, :description].each do |item|
        content = spec.send(item)
        if /TODO|FIXME/ =~ content
          data[:item] = item
          data[:content] = content
          errors << (format % data)
        end
      end
      unless errors.empty?
        raise errors.join("\n")
      end
    end
  end
end
define_pdf_task() click to toggle source
# File lib/rabbit/task/theme.rb, line 137
def define_pdf_task
  desc(_("Generate all PDFs"))
  task :pdf
  theme_benchmark_locales.each do |locale|
    task :pdf => "pdf:#{locale}"
  end

  namespace :pdf do
    theme_benchmark_locales.each do |locale|
      pdf_path = theme_benchmark_pdf_path(locale)
      files_without_pdf = spec.files.reject do |file|
        file.start_with?("#{@pdf_dir}/")
      end
      file pdf_path => files_without_pdf do
        mkdir_p(@pdf_dir)
        rabbit("--theme", ".",
               "--print",
               "--output-filename", pdf_path,
               "rabbit-theme-benchmark-#{locale}.gem")
      end

      desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
      task locale => pdf_path do
      end
    end
  end
end
define_publish_task() click to toggle source
# File lib/rabbit/task/theme.rb, line 165
def define_publish_task
  desc(_("Publish the theme to all available targets"))
  task :publish

  publish_tasks = []
  namespace :publish do
    rubygems_user = @theme.author.rubygems_user
    if rubygems_user
      desc(_("Publish the theme to %s") % "RubyGems.org")
      task :rubygems => :gem do
        pusher = GemPusher.new(gem_path, rubygems_user)
        pusher.push
      end
      publish_tasks << :rubygems
    end
  end
  task :publish => publish_tasks.collect {|task| "publish:#{task}"}
end
define_run_task() click to toggle source
# File lib/rabbit/task/theme.rb, line 93
def define_run_task
  desc(_("Show theme benchmark slide with this theme"))
  task :run do
    rabbit("--theme", ".", _("rabbit-theme-benchmark-en.gem"))
  end
end
gem_path() click to toggle source
# File lib/rabbit/task/theme.rb, line 184
def gem_path
  File.join(@package_dir, "#{spec.name}-#{spec.version}.gem")
end
homepage() click to toggle source
# File lib/rabbit/task/theme.rb, line 196
def homepage
  "http://theme.rabbit-shocker.org/themes/#{@theme.id}/"
end
load_theme_configuration() click to toggle source
# File lib/rabbit/task/theme.rb, line 50
def load_theme_configuration
  theme_conf = ThemeConfiguration.new(@logger)
  theme_conf.load
  theme_conf
end
rabbit(*arguments) click to toggle source
# File lib/rabbit/task/theme.rb, line 200
def rabbit(*arguments)
  Rabbit::Command::Rabbit.run(*arguments)
end
theme_benchmark_locales() click to toggle source
# File lib/rabbit/task/theme.rb, line 192
def theme_benchmark_locales
  ["en", "ja"]
end
theme_benchmark_pdf_path(locale) click to toggle source
# File lib/rabbit/task/theme.rb, line 188
def theme_benchmark_pdf_path(locale)
  File.join(@pdf_dir, "theme-benchmark-#{locale}.pdf")
end