rails_stuff 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -0
 - data/Gemfile +2 -0
 - data/README.md +61 -2
 - data/lib/assets/javascripts/rails_stuff/plugin_manager.coffee +40 -0
 - data/lib/assets/stylesheets/rails_stuff/_media_queries.scss +25 -0
 - data/lib/rails_stuff/{railtie.rb → engine.rb} +1 -1
 - data/lib/rails_stuff/version.rb +1 -1
 - data/lib/rails_stuff.rb +1 -1
 - metadata +5 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 65e05ba6c678beac4cb3ffe9b343451f18e04b0f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 15bcb1d1b7512b366a33ba672c0b79ab9cc3161a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5a7094c08403ab00894951527b8652d66d9ac841e95834daab95d1e9ec4fe131aab178b52aa91c8d363789cba98a9c922a88da9108dcf37d55ff8efc4f3b785c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: fc876d2f0ae219d76109e91450e93cef8474ea22ab40f4eeea0a65da1732c86d21f8047e1b718d1c6baf92b089e811b7352250cbc4c838af45b1cc27821865e4
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -47,7 +47,21 @@ Collection of useful modules for Rails. 
     | 
|
| 
       47 
47 
     | 
    
         
             
            - __Forms__
         
     | 
| 
       48 
48 
     | 
    
         
             
              `hidden_params_fields` to bypass query params in GET-forms.
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
            __[Helpers usage](#helpers)__
         
     | 
| 
      
 50 
     | 
    
         
            +
            __[Helpers usage](#helpers-usage)__
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            #### Test helpers:
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            - __Response__
         
     | 
| 
      
 55 
     | 
    
         
            +
              `#json_body` to test json responses.
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            __[Test helpers usage](#test-helpers-usage)__
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            #### Assets:
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            - __MediaQueries__
         
     | 
| 
      
 62 
     | 
    
         
            +
              `@media #{$sm-up} and #{$portrait} { ... }` queries for SASS.
         
     | 
| 
      
 63 
     | 
    
         
            +
            - __[PluginManager](#pluginmanager)__
         
     | 
| 
      
 64 
     | 
    
         
            +
              Simple way to create jQuery plugins using classes.
         
     | 
| 
       51 
65 
     | 
    
         | 
| 
       52 
66 
     | 
    
         
             
            ## Installation
         
     | 
| 
       53 
67 
     | 
    
         | 
| 
         @@ -307,7 +321,7 @@ params.require_permitted(:access_token, :refresh_token) 
     | 
|
| 
       307 
321 
     | 
    
         
             
            params.permit(:access_token, :refresh_token).require(:access_token, :refresh_token)
         
     | 
| 
       308 
322 
     | 
    
         
             
            ```
         
     | 
| 
       309 
323 
     | 
    
         | 
| 
       310 
     | 
    
         
            -
            ### Helpers
         
     | 
| 
      
 324 
     | 
    
         
            +
            ### Helpers usage
         
     | 
| 
       311 
325 
     | 
    
         | 
| 
       312 
326 
     | 
    
         
             
            Include helper module into `ApplicationHelper`.
         
     | 
| 
       313 
327 
     | 
    
         
             
            Or use `RailsStuff::Helpers::All` to include all helpers together.
         
     | 
| 
         @@ -342,6 +356,51 @@ Translation helpers are cached, so there is no need to cache it by yourself in 
     | 
|
| 
       342 
356 
     | 
    
         
             
            template if you want to decrease computations. And be aware of it if you
         
     | 
| 
       343 
357 
     | 
    
         
             
            switch locales while rendering single view.
         
     | 
| 
       344 
358 
     | 
    
         | 
| 
      
 359 
     | 
    
         
            +
            ### Test helpers usage
         
     | 
| 
      
 360 
     | 
    
         
            +
             
     | 
| 
      
 361 
     | 
    
         
            +
            Add `require 'rails_stuff/test_helpers/rails'` to `test_helper.rb`.
         
     | 
| 
      
 362 
     | 
    
         
            +
             
     | 
| 
      
 363 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 364 
     | 
    
         
            +
            assert_equal({'id' => 1, 'name' => 'John'}, response.json_body)
         
     | 
| 
      
 365 
     | 
    
         
            +
            assert_equal('John', response.json_body['name'])
         
     | 
| 
      
 366 
     | 
    
         
            +
            assert_equal('John', response.json_body.name)
         
     | 
| 
      
 367 
     | 
    
         
            +
             
     | 
| 
      
 368 
     | 
    
         
            +
            # with rspec-its
         
     | 
| 
      
 369 
     | 
    
         
            +
            subject { get :show, id: resource.id }
         
     | 
| 
      
 370 
     | 
    
         
            +
            its(:json_body) { should include 'id' => 1 }
         
     | 
| 
      
 371 
     | 
    
         
            +
            its('json_body.name') { should eq 'John' }
         
     | 
| 
      
 372 
     | 
    
         
            +
            ```
         
     | 
| 
      
 373 
     | 
    
         
            +
             
     | 
| 
      
 374 
     | 
    
         
            +
            `.json_body` helper requires `gem 'hashie'`.
         
     | 
| 
      
 375 
     | 
    
         
            +
             
     | 
| 
      
 376 
     | 
    
         
            +
            Note that `hashie` conflicts with `Hash` methods, so `.json_body.key` or
         
     | 
| 
      
 377 
     | 
    
         
            +
            `.json_body.hash` will not work as expected (or at all).
         
     | 
| 
      
 378 
     | 
    
         
            +
            Use `json_body['key']` instead.
         
     | 
| 
      
 379 
     | 
    
         
            +
             
     | 
| 
      
 380 
     | 
    
         
            +
            ### PluginManager
         
     | 
| 
      
 381 
     | 
    
         
            +
             
     | 
| 
      
 382 
     | 
    
         
            +
            Provides simple way to create jQuery plugins. Create class and PluginManager
         
     | 
| 
      
 383 
     | 
    
         
            +
            will create jQuery function for it. It'll create instance of class for each
         
     | 
| 
      
 384 
     | 
    
         
            +
            jQuery element and prevent calling constructor twice.
         
     | 
| 
      
 385 
     | 
    
         
            +
             
     | 
| 
      
 386 
     | 
    
         
            +
            ```coffee
         
     | 
| 
      
 387 
     | 
    
         
            +
            PluginManager.add 'myPlugin', class
         
     | 
| 
      
 388 
     | 
    
         
            +
              constructor: (@$element, @options) ->
         
     | 
| 
      
 389 
     | 
    
         
            +
                 # ...
         
     | 
| 
      
 390 
     | 
    
         
            +
             
     | 
| 
      
 391 
     | 
    
         
            +
              customAction: (options)->
         
     | 
| 
      
 392 
     | 
    
         
            +
                 # ...
         
     | 
| 
      
 393 
     | 
    
         
            +
             
     | 
| 
      
 394 
     | 
    
         
            +
              # Add initializers
         
     | 
| 
      
 395 
     | 
    
         
            +
              $ -> $('[data-my-plugin]').myPlugin()
         
     | 
| 
      
 396 
     | 
    
         
            +
              # or
         
     | 
| 
      
 397 
     | 
    
         
            +
              $(document).on 'click', '[data-my-plugin]', (e) ->
         
     | 
| 
      
 398 
     | 
    
         
            +
                $(@).myPlugin('customAction', event: e)
         
     | 
| 
      
 399 
     | 
    
         
            +
             
     | 
| 
      
 400 
     | 
    
         
            +
            # Or use it manually
         
     | 
| 
      
 401 
     | 
    
         
            +
            $('.selector').myPlugin().myPlugin('customAction')
         
     | 
| 
      
 402 
     | 
    
         
            +
            ```
         
     | 
| 
      
 403 
     | 
    
         
            +
             
     | 
| 
       345 
404 
     | 
    
         
             
            ## Development
         
     | 
| 
       346 
405 
     | 
    
         | 
| 
       347 
406 
     | 
    
         
             
            After checking out the repo, run `bin/setup` to install dependencies.
         
     | 
| 
         @@ -0,0 +1,40 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Provides simple way to create jQuery plugins. Create class and PluginManager
         
     | 
| 
      
 2 
     | 
    
         
            +
            # will create jQuery function for it. It'll create instance of class for each
         
     | 
| 
      
 3 
     | 
    
         
            +
            # jQuery element and prevent calling constructor twice.
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            #     PluginManager.add 'myPlugin', class
         
     | 
| 
      
 6 
     | 
    
         
            +
            #       constructor: (@$element, @options) ->
         
     | 
| 
      
 7 
     | 
    
         
            +
            #          # ...
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #       customAction: (options)->
         
     | 
| 
      
 10 
     | 
    
         
            +
            #          # ...
         
     | 
| 
      
 11 
     | 
    
         
            +
            #
         
     | 
| 
      
 12 
     | 
    
         
            +
            #       # Add initializers
         
     | 
| 
      
 13 
     | 
    
         
            +
            #       $ -> $('[data-my-plugin]').myPlugin()
         
     | 
| 
      
 14 
     | 
    
         
            +
            #       # or
         
     | 
| 
      
 15 
     | 
    
         
            +
            #       $(document).on 'click', '[data-my-plugin]', (e) ->
         
     | 
| 
      
 16 
     | 
    
         
            +
            #         $(@).myPlugin('customAction', event: e)
         
     | 
| 
      
 17 
     | 
    
         
            +
            #
         
     | 
| 
      
 18 
     | 
    
         
            +
            #     # Or use it manually
         
     | 
| 
      
 19 
     | 
    
         
            +
            #     $('.selector').myPlugin().myPlugin('customAction')
         
     | 
| 
      
 20 
     | 
    
         
            +
            class window.PluginManager
         
     | 
| 
      
 21 
     | 
    
         
            +
              @plugins = {}
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              # Takes class and creates jQuery's plugin function for it.
         
     | 
| 
      
 24 
     | 
    
         
            +
              # This function simply creates class instance for each element
         
     | 
| 
      
 25 
     | 
    
         
            +
              # and prevents creating multiple instances on single element.
         
     | 
| 
      
 26 
     | 
    
         
            +
              #
         
     | 
| 
      
 27 
     | 
    
         
            +
              # Name is set explicitly to avoid errors when using uglifier.
         
     | 
| 
      
 28 
     | 
    
         
            +
              @add: (pluginName, klass) ->
         
     | 
| 
      
 29 
     | 
    
         
            +
                data_index = "#{pluginName}.instance"
         
     | 
| 
      
 30 
     | 
    
         
            +
                @plugins[pluginName] = klass
         
     | 
| 
      
 31 
     | 
    
         
            +
                jQuery.fn[pluginName] = (action, options) ->
         
     | 
| 
      
 32 
     | 
    
         
            +
                  if typeof action is 'object'
         
     | 
| 
      
 33 
     | 
    
         
            +
                    options = action
         
     | 
| 
      
 34 
     | 
    
         
            +
                    action = null
         
     | 
| 
      
 35 
     | 
    
         
            +
                  @each ->
         
     | 
| 
      
 36 
     | 
    
         
            +
                    $this = jQuery @
         
     | 
| 
      
 37 
     | 
    
         
            +
                    unless instance = $this.data data_index
         
     | 
| 
      
 38 
     | 
    
         
            +
                      instance = new klass $this, options
         
     | 
| 
      
 39 
     | 
    
         
            +
                      $this.data data_index, instance
         
     | 
| 
      
 40 
     | 
    
         
            +
                    instance[action](options) if action
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // Foundation-style media queries.
         
     | 
| 
      
 2 
     | 
    
         
            +
            // Works with Bootstrap3 out of the box.
         
     | 
| 
      
 3 
     | 
    
         
            +
            // Without bootstrap just define variables:
         
     | 
| 
      
 4 
     | 
    
         
            +
            //   screen-xs-max, screen-{sm,md}-{min,max}, screen-lg-min
         
     | 
| 
      
 5 
     | 
    
         
            +
            //
         
     | 
| 
      
 6 
     | 
    
         
            +
            // Usage:
         
     | 
| 
      
 7 
     | 
    
         
            +
            //
         
     | 
| 
      
 8 
     | 
    
         
            +
            //   @media #{$sm-up} { ... }
         
     | 
| 
      
 9 
     | 
    
         
            +
            //   @media #{$sm-only} and #{$landscape} { ... }
         
     | 
| 
      
 10 
     | 
    
         
            +
            $screen: "only screen" !default;
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            $landscape: "(orientation: landscape)" !default;
         
     | 
| 
      
 13 
     | 
    
         
            +
            $portrait: "(orientation: portrait)" !default;
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            $xs-up: $screen !default;
         
     | 
| 
      
 16 
     | 
    
         
            +
            $xs-only: "(max-width: #{$screen-xs-max})" !default;
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            $sm-up: "(min-width:#{$screen-sm-min})" !default;
         
     | 
| 
      
 19 
     | 
    
         
            +
            $sm-only: "(min-width:#{$screen-sm-min}) and (max-width:#{$screen-sm-max})" !default;
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            $md-up: "(min-width:#{$screen-md-min})" !default;
         
     | 
| 
      
 22 
     | 
    
         
            +
            $md-only: "(min-width:#{$screen-md-min}) and (max-width:#{$screen-md-max})" !default;
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            $lg-up: "(min-width:#{$screen-lg-min})" !default;
         
     | 
| 
      
 25 
     | 
    
         
            +
            $lg-only: "(min-width:#{$screen-lg-min})" !default;
         
     | 
    
        data/lib/rails_stuff/version.rb
    CHANGED
    
    
    
        data/lib/rails_stuff.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rails_stuff
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Max Melentiev
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-09-21 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -72,8 +72,11 @@ files: 
     | 
|
| 
       72 
72 
     | 
    
         
             
            - bin/git-hooks/pre-commit
         
     | 
| 
       73 
73 
     | 
    
         
             
            - bin/install_git_hooks
         
     | 
| 
       74 
74 
     | 
    
         
             
            - bin/setup
         
     | 
| 
      
 75 
     | 
    
         
            +
            - lib/assets/javascripts/rails_stuff/plugin_manager.coffee
         
     | 
| 
      
 76 
     | 
    
         
            +
            - lib/assets/stylesheets/rails_stuff/_media_queries.scss
         
     | 
| 
       75 
77 
     | 
    
         
             
            - lib/net/http/debug.rb
         
     | 
| 
       76 
78 
     | 
    
         
             
            - lib/rails_stuff.rb
         
     | 
| 
      
 79 
     | 
    
         
            +
            - lib/rails_stuff/engine.rb
         
     | 
| 
       77 
80 
     | 
    
         
             
            - lib/rails_stuff/helpers.rb
         
     | 
| 
       78 
81 
     | 
    
         
             
            - lib/rails_stuff/helpers/all.rb
         
     | 
| 
       79 
82 
     | 
    
         
             
            - lib/rails_stuff/helpers/bootstrap.rb
         
     | 
| 
         @@ -84,7 +87,6 @@ files: 
     | 
|
| 
       84 
87 
     | 
    
         
             
            - lib/rails_stuff/helpers/translation.rb
         
     | 
| 
       85 
88 
     | 
    
         
             
            - lib/rails_stuff/nullify_blank_attrs.rb
         
     | 
| 
       86 
89 
     | 
    
         
             
            - lib/rails_stuff/params_parser.rb
         
     | 
| 
       87 
     | 
    
         
            -
            - lib/rails_stuff/railtie.rb
         
     | 
| 
       88 
90 
     | 
    
         
             
            - lib/rails_stuff/random_uniq_attr.rb
         
     | 
| 
       89 
91 
     | 
    
         
             
            - lib/rails_stuff/redis_storage.rb
         
     | 
| 
       90 
92 
     | 
    
         
             
            - lib/rails_stuff/resources_controller.rb
         
     |