Skip to content

Commit

Permalink
Updater task and add [email protected] assets
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed May 29, 2017
1 parent 4ed7887 commit 186d093
Show file tree
Hide file tree
Showing 7 changed files with 2,349 additions and 23 deletions.
51 changes: 36 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,64 @@
# PopperJs

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/popper_js`. To experiment with that code, run `bin/console` for an interactive prompt.

TODO: Delete this and the text above, and describe your gem
This gem packages [popper.js](https://popper.js.org/) for use with Sprockets,
the Rails asset pipeline.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'popper_js'
gem 'popper_js', '~> 1.9.9'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install popper_js
```bash
bundle
```

## Usage

TODO: Write usage instructions here
Require `popper` from your `application.js`:

```js
//= require popper
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
After checking out the repo, run `bin/setup` to install dependencies.
Then, run `rake spec` to run the tests.
You can also run `bin/console` for an interactive prompt that will allow you
to experiment.

To update the bundled Popper.js assets to the latest version, run:

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
```bash
rake update
```

To install this gem onto your local machine, run `bundle exec rake install`.
To release a new version, update the version number in `version.rb`,
and then run `bundle exec rake release`, which will create a git tag
for the version, push git commits and tags,
and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/popper_js. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
Bug reports and pull requests are welcome on GitHub
at https://github.com/glebm/popper_js-rubygem. This project is intended to be a
safe, welcoming space for collaboration, and contributors are expected to adhere
to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
The gem is available as open source under the terms of
the [MIT License](http://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the PopperJs project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/popper_js/blob/master/CODE_OF_CONDUCT.md).
Everyone interacting in the PopperJs project’s codebases, issue trackers,
chat rooms and mailing lists is expected to follow the [code of conduct].

[code of conduct]: https://github.com/glebm/popper_js-rubygem/blob/master/CODE_OF_CONDUCT.md
34 changes: 34 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

desc 'Update popper.js assets to the latest npm release'
task :update do
require 'net/http'
require 'uri'
uri = URI.parse('https://unpkg.com/popper.js')
fetch = lambda do
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
http.request(Net::HTTP::Get.new(uri.path, 'User-Agent' => 'Ruby'))
end
case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
# unpkg.com returns a relative URL in the `location` field.
uri.path = URI.parse(response['location']).path
fetch.call
else
response.error!
end
end
src = fetch.call.body
# Remove the source mapping comment as this gem does not bundle source maps:
src.sub!(%r{^//# sourceMappingURL=.*\n\z}, '')
File.write(File.join('assets/javascripts/popper.js'), src)

version_path = File.join('lib/popper_js/version.rb')
File.write version_path,
File.read(version_path)
.sub(/VERSION = '.*?'/,
"VERSION = '#{uri.path.split('@')[-1]}'")

STDERR.puts "Updated from #{uri}"
end

RSpec::Core::RakeTask.new(:spec)

task default: :spec
Loading

0 comments on commit 186d093

Please sign in to comment.