Sha256: 8635f1544f70f30a5376da5f1a9cc4a0b34751d218ec75f9b5a1a6a023b57eb0

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

require 'thor'
require 'json'

class SourceFile < Thor
  include Thor::Actions

  desc 'fetch source files', 'fetch source files from GitHub'
  def fetch remote, branch
    self.destination_root = 'vendor/assets'
    get "#{remote}/raw/#{branch}/public/chosen-sprite.png", 'images/chosen-sprite.png'
    get "#{remote}/raw/#{branch}/public/chosen-sprite@2x.png", 'images/chosen-sprite@2x.png'
    get "#{remote}/raw/#{branch}/sass/chosen.scss", 'stylesheets/chosen.css.scss'
    get "#{remote}/raw/#{branch}/coffee/lib/abstract-chosen.coffee", 'javascripts/lib/abstract-chosen.coffee'
    get "#{remote}/raw/#{branch}/coffee/lib/select-parser.coffee", 'javascripts/lib/select-parser.coffee'
    get "#{remote}/raw/#{branch}/coffee/chosen.jquery.coffee", 'javascripts/chosen.jquery.coffee'
    get "#{remote}/raw/#{branch}/coffee/chosen.proto.coffee", 'javascripts/chosen.proto.coffee'
    get "#{remote}/raw/#{branch}/package.json", 'package.json'
    bump_version
  end

  desc 'eject class from closure', 'eject javascript library class from closure'
  def eject_javascript_class_from_closure
    self.destination_root = 'vendor/assets'
    inside destination_root do
      append_to_file 'javascripts/lib/abstract-chosen.coffee' do
        "\nwindow.AbstractChosen = AbstractChosen\n"
      end
      append_to_file 'javascripts/lib/select-parser.coffee' do
        "\n\nwindow.SelectParser = SelectParser\n"
      end
    end
  end

  desc 'clean up useless files', 'clean up useless files'
  def cleanup
    self.destination_root = 'vendor/assets'
    remove_file 'package.json'
  end

  protected

  def bump_version
    inside destination_root do
      package_json = JSON.load(File.open('package.json'))
      version = package_json['version']
      gsub_file '../../lib/chosen-rails/version.rb', /CHOSEN_VERSION\s=\s'(\d|\.)+'$/ do |match|
        %Q{CHOSEN_VERSION = '#{version}'}
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
chosen-rails-1.2.0 lib/chosen-rails/source_file.rb
chosen-rails-1.1.1 lib/chosen-rails/source_file.rb
chosen-rails-1.1.0 lib/chosen-rails/source_file.rb
chosen-rails-adding-1.0.2.1 lib/chosen-rails-adding/source_file.rb
chosen-rails-1.0.2 lib/chosen-rails/source_file.rb
chosen-rails-1.0.1 lib/chosen-rails/source_file.rb
chosen-rails-1.0.0 lib/chosen-rails/source_file.rb