Giter VIP home page Giter VIP logo

unpoly-rails's Introduction

Progressive enhancement for HTML

Unpoly enhances your HTML with attributes to build dynamic UI on the server.

Unpoly works with any language or framework. It plays nice with existing code, and gracefully degrades without JavaScript.

This branch tracks the current major version, Unpoly 3.x.
If you're using Unpoly 2.x, use the 2.x-stable branch.
If you're using Unpoly 1.x or 0.x, use the 1.x-stable branch.

Getting started

Development

Installing development dependencies

To build Unpoly you require Node.js, Webpack and other npm packages.

Install the Node version from .nvmrc.

To install Webpack and other required npm packages, run:

npm install

Quick start

The following will build the library and open a web browser with the test suite:

npm run dev

To run individual tasks instead, see below.

Building the library

Tests don't consume the sources directly, but from a transpiled build in dist/.

To make fresh build, run:

npm run build-dev

This will build transpiled files such as:

dist/unpoly.js
dist/unpoly.css
dist/unpoly-migrate.js
dist/jasmine.js
dist/specs.js

There is also a task npm run build for a production build. This does not build files for testing, but also outputs minified versions.

Watching files for changes

During development it is impractical to make a full build after every change. Instead it is recommend to watch the project:

npm run watch-dev

This will make a fresh build and then watch the project for changes to the source files. When a source changes, affected build files are automatically recompiled. The incremental recompilation is much faster than a full build.

Running tests

Tests run using a browser-based Jasmine runner.

To start a web server serving the Jasmine runner:

npm run test

This will open a server on http://localhost:4000 and opens that URL with your default browser.

In addition to the unit tests, there is an optional support repo unpoly-manual-tests. It contains a Rails app to play with Unpoly features that are hard to test well with a unit test. E.g. the visual look of overlays, or edge cases when booting Unpoly.

Making a new release

You can use this repository to publish a new version of the unpoly npm package.

The release process currently requires Ruby. To install these dependencies:

  • Install the Ruby version from .ruby-version
  • Run bundle install

There is a guided CLI interface to lead you through the release process. To start the process run:

bundle exec rake release:process

Credits

unpoly-rails's People

Contributors

iaddict avatar kratob avatar niklashae avatar triskweline avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

unpoly-rails's Issues

Safe parsing of params

Security scanners causing unpoly-rails to fail on certain requests. It would be easier for a application integration to drop invalid requests instead of raising errors.

I created a repository to reproduce the issue. But I assume that all Rails application with unpoly-rails in the bundle will raise an error when calling /?_up_context_changes={}&_up_events[$eq]=[].

Maybe the fix would be similar to #3 (comment), to not raise an error in case of invalid params?

Proposal: raise a custom error for JSON parse errors

Hi,

I'm trying to get rid of some notification noise that comes from

ActiveSupport::JSON.decode(string)
whenever ActiveSupport::JSON.decode is not able to parse JSON correctly and raises a JSON::ParserError. This happens when automatic security scanners try out different strings in the custom unpoly-rails headers.

Since the JSON.parse_error error is very generic, it's hard for me to specifically ignore or handle it globally. It would be way easier for me, if unpoly-rails would raise a simple custom error that is_a Unpoly::Rails::Error.

E.g.

def json_decode(string)
  ActiveSupport::JSON.decode(string)
rescue ActiveSupport::JSON.parse_error
  raise MalformedHeaderError
end

Please let me know if you need help or more information ๐Ÿ‘ Please feel free to close the issue if you don't agree with the proposal.

Brittle check if original_url contains _up_ query parameters

To decide if a URI contains _up_* parameters, a simple String#includes? check on the original url is made.
This causes an error on the following line, when the path compontent contains this prefix, but does not include any query parameters:

original_url.include?(Field::PARAM_PREFIX) or return original_url

# this makes the following code fail, because the query is nil
URI.parse('https://example.com/sign_up_reminder/').query.split('&')
# => NoMethodError: undefined method `split' for nil:NilClass

Proposal: Log if a header cannot be parsed into a HashWithIndifferentAccess

Hi,

sending anything that is valid JSON but will not result in a Hash (e.g. "1", "test", []) in at least the X-Up-Context and X-Up-Fail-Context headers leads to exceptions. These exceptions are mostly generated by security-scanners, similar to #3.

Since for the resolution of #3 we decided to log instead of raising out, I'd suggest to handle such a case similiarly. This would reduce the noise generated by such scanners.

Example:

get "/some-unpoly-rails-route", headers: { "X-Up-Fail-Context" => '"somesnippet"' }
get "/some-unpoly-rails-route", headers: { "X-Up-Fail-Context" => '42' }

Backtrace:

Unpoly::Rails::Error:
       Constructor args must be an ActiveSupport::HashWithIndifferentaccess
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change/context.rb:73:in `ensure_indifferent_access'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change/context.rb:12:in `initialize'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change.rb:192:in `new'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change.rb:192:in `context'
     # (eval):16:in `context'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change.rb:200:in `context_changes'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change.rb:260:in `block in after_action'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change/field_definition.rb:28:in `no_vary'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/change.rb:254:in `after_action'
     # .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/unpoly-rails-3.7.2/lib/unpoly/rails/controller.rb:12:in `block in prepended'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.