voltron-flash 0.1.1
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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/voltron-flash.js +148 -0
- data/app/assets/stylesheets/voltron-flash.scss +86 -0
- data/app/helpers/voltron/flash_helper.rb +11 -0
- data/app/views/voltron/flash.html.erb +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/templates/app/assets/javascripts/voltron-flash.js +148 -0
- data/lib/generators/templates/app/assets/stylesheets/voltron-flash.scss +86 -0
- data/lib/generators/templates/app/views/voltron/flash.html.erb +26 -0
- data/lib/generators/voltron/flash/install/assets_generator.rb +27 -0
- data/lib/generators/voltron/flash/install_generator.rb +41 -0
- data/lib/voltron/config/flash.rb +33 -0
- data/lib/voltron/flash.rb +55 -0
- data/lib/voltron/flash/engine.rb +16 -0
- data/lib/voltron/flash/version.rb +5 -0
- data/voltron-flash.gemspec +33 -0
- metadata +222 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 5def506009a6ae42bb7bbeb189e5262a8257bef7
         | 
| 4 | 
            +
              data.tar.gz: cb185dcedd211c8bfa1088cdc425d16e74f51861
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: deb79607add7c0ba5a82a8557e78e1caf0bf55e33ecb6fbaa7c1fec41794b1714e03ba516aae13fd462778db1e6dced36bd5842382d069ebcf953e47bc85303b
         | 
| 7 | 
            +
              data.tar.gz: 73cacb5b7da4d052e92487995d11f8e94a384b4de2293ba6ae7996599e308856d3b0d688b973e72668c98f8276ced8109ce6c21dde15f280c168709831d92e0d
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/CODE_OF_CONDUCT.md
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            # Contributor Code of Conduct
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            As contributors and maintainers of this project, and in the interest of
         | 
| 4 | 
            +
            fostering an open and welcoming community, we pledge to respect all people who
         | 
| 5 | 
            +
            contribute through reporting issues, posting feature requests, updating
         | 
| 6 | 
            +
            documentation, submitting pull requests or patches, and other activities.
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            We are committed to making participation in this project a harassment-free
         | 
| 9 | 
            +
            experience for everyone, regardless of level of experience, gender, gender
         | 
| 10 | 
            +
            identity and expression, sexual orientation, disability, personal appearance,
         | 
| 11 | 
            +
            body size, race, ethnicity, age, religion, or nationality.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            Examples of unacceptable behavior by participants include:
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            * The use of sexualized language or imagery
         | 
| 16 | 
            +
            * Personal attacks
         | 
| 17 | 
            +
            * Trolling or insulting/derogatory comments
         | 
| 18 | 
            +
            * Public or private harassment
         | 
| 19 | 
            +
            * Publishing other's private information, such as physical or electronic
         | 
| 20 | 
            +
              addresses, without explicit permission
         | 
| 21 | 
            +
            * Other unethical or unprofessional conduct
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            Project maintainers have the right and responsibility to remove, edit, or
         | 
| 24 | 
            +
            reject comments, commits, code, wiki edits, issues, and other contributions
         | 
| 25 | 
            +
            that are not aligned to this Code of Conduct, or to ban temporarily or
         | 
| 26 | 
            +
            permanently any contributor for other behaviors that they deem inappropriate,
         | 
| 27 | 
            +
            threatening, offensive, or harmful.
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            By adopting this Code of Conduct, project maintainers commit themselves to
         | 
| 30 | 
            +
            fairly and consistently applying these principles to every aspect of managing
         | 
| 31 | 
            +
            this project. Project maintainers who do not follow or enforce the Code of
         | 
| 32 | 
            +
            Conduct may be permanently removed from the project team.
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            This code of conduct applies both within project spaces and in public spaces
         | 
| 35 | 
            +
            when an individual is representing the project or its community.
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            Instances of abusive, harassing, or otherwise unacceptable behavior may be
         | 
| 38 | 
            +
            reported by contacting a project maintainer at eric.hainer@gmail.com. All
         | 
| 39 | 
            +
            complaints will be reviewed and investigated and will result in a response that
         | 
| 40 | 
            +
            is deemed necessary and appropriate to the circumstances. Maintainers are
         | 
| 41 | 
            +
            obligated to maintain confidentiality with regard to the reporter of an
         | 
| 42 | 
            +
            incident.
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            This Code of Conduct is adapted from the [Contributor Covenant][homepage],
         | 
| 45 | 
            +
            version 1.3.0, available at
         | 
| 46 | 
            +
            [http://contributor-covenant.org/version/1/3/0/][version]
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            [homepage]: http://contributor-covenant.org
         | 
| 49 | 
            +
            [version]: http://contributor-covenant.org/version/1/3/0/
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2016 Eric Hainer
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            +
            all copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            [](https://travis-ci.org/ehainer/voltron-flash)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # Voltron::Flash
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            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/voltron/flash`. To experiment with that code, run `bin/console` for an interactive prompt.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            TODO: Delete this and the text above, and describe your gem
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ## Installation
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Add this line to your application's Gemfile:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ```ruby
         | 
| 14 | 
            +
            gem 'voltron-flash'
         | 
| 15 | 
            +
            ```
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            And then execute:
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                $ bundle
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Or install it yourself as:
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                $ gem install voltron-flash
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ## Usage
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            TODO: Write usage instructions here
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ## Development
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            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.
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            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).
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            ## Contributing
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/voltron-flash. 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.
         | 
| 38 | 
            +
             | 
| 39 | 
            +
             | 
| 40 | 
            +
            ## License
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
         | 
| 43 | 
            +
             | 
    
        data/Rakefile
    ADDED
    
    
| @@ -0,0 +1,148 @@ | |
| 1 | 
            +
            //= require voltron
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Voltron.addModule('Flash', function(){
         | 
| 4 | 
            +
              var _defaults = {
         | 
| 5 | 
            +
                class: '',
         | 
| 6 | 
            +
                bind: 'body',
         | 
| 7 | 
            +
                id: 'flashes',
         | 
| 8 | 
            +
                containerClass: '',
         | 
| 9 | 
            +
                addMethod: 'prepend',
         | 
| 10 | 
            +
                revealMethod: 'slideDown',
         | 
| 11 | 
            +
                revealTime: 200,
         | 
| 12 | 
            +
                concealMethod: 'slideUp',
         | 
| 13 | 
            +
                concealTime: 200,
         | 
| 14 | 
            +
                autoClose: false,
         | 
| 15 | 
            +
                autoCloseAfter: 5000,
         | 
| 16 | 
            +
                autoAdd: true
         | 
| 17 | 
            +
              };
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              return {
         | 
| 20 | 
            +
                initialize: function(){
         | 
| 21 | 
            +
                  Voltron('Dispatch/addEventWatcher', 'click');
         | 
| 22 | 
            +
                  this.on('click:close-alert', 'click:close-notice', 'click:close-warning', this.clear);
         | 
| 23 | 
            +
                  this.addListener();
         | 
| 24 | 
            +
                },
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                setConfig: function(options){
         | 
| 27 | 
            +
                  _defaults = $.extend(_defaults, options);
         | 
| 28 | 
            +
                  this.afterConfigChange();
         | 
| 29 | 
            +
                  return this;
         | 
| 30 | 
            +
                },
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                addListener: function(){
         | 
| 33 | 
            +
                  $(document).ajaxComplete(function(event, request){
         | 
| 34 | 
            +
                    if(_defaults.autoAdd){
         | 
| 35 | 
            +
                      var flashes = request.getResponseHeader(Voltron.getConfig('flash/header', 'X-Flash'));
         | 
| 36 | 
            +
                      var flash = $.parseJSON(flashes);
         | 
| 37 | 
            +
                      if(flash){
         | 
| 38 | 
            +
                        Voltron('Flash/new', flash);
         | 
| 39 | 
            +
                      }
         | 
| 40 | 
            +
                    }
         | 
| 41 | 
            +
                  });
         | 
| 42 | 
            +
                },
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                new: function(flashes, options){
         | 
| 45 | 
            +
                  options = $.extend(_defaults, options);
         | 
| 46 | 
            +
                  var flash;
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  this.getContainer(options).addClass(options.class);
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  $.each(flashes, $.proxy(function(type, messages){
         | 
| 51 | 
            +
                    flash = this.addFlash(type, messages, options);
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    if(flash.find('.flash-message').length == 1){
         | 
| 54 | 
            +
                      // If this is the first flash message, reveal the whole container
         | 
| 55 | 
            +
                      flash.find('.flash-message').show();
         | 
| 56 | 
            +
                      flash[options.revealMethod](options.revealTime);
         | 
| 57 | 
            +
                    }else{
         | 
| 58 | 
            +
                      // Otherwise reveal just the newest message(s)
         | 
| 59 | 
            +
                      flash.find('.flash-message')[options.revealMethod](options.revealTime);
         | 
| 60 | 
            +
                    }
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    if(options.autoClose){
         | 
| 63 | 
            +
                      setTimeout(function(){
         | 
| 64 | 
            +
                        V('Flash/clear', { element: flash });
         | 
| 65 | 
            +
                      }, options.autoCloseAfter);
         | 
| 66 | 
            +
                    }
         | 
| 67 | 
            +
                  }, this));
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  return this;
         | 
| 70 | 
            +
                },
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                addFlash: function(type, messages, options){
         | 
| 73 | 
            +
                  var flash = this.getFlash(type);
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  flash.append($.map($.makeArray(messages), function(message){
         | 
| 76 | 
            +
                    return $('<p />', { class: 'flash-message' }).html(message).hide();
         | 
| 77 | 
            +
                  }));
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  if(!Voltron.getConfig('flash/group') || !flash.find('.flash-close').length){
         | 
| 80 | 
            +
                    flash.append($('<button />', { class: 'flash-close', type: 'button', id: 'close-' + type, 'data-dispatch': 'click' }));
         | 
| 81 | 
            +
                  }
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  if(!this.getContainer(options).length){
         | 
| 84 | 
            +
                    Voltron.debug('warn', 'Element with which to bind flash messages to could not be found. The bind selector given was %o. Please ensure an element matching the given selector exists.', options.bind);
         | 
| 85 | 
            +
                  }
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  this.getContainer(options).append(flash);
         | 
| 88 | 
            +
                  return flash;
         | 
| 89 | 
            +
                },
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                getFlash: function(type){
         | 
| 92 | 
            +
                  if(Voltron.getConfig('flash/group') && $('.flash.' + type).length){
         | 
| 93 | 
            +
                    return $('.flash.' + type).first();
         | 
| 94 | 
            +
                  }
         | 
| 95 | 
            +
                  return $('<div />', { class: ['flash', type].join(' ') }).hide();
         | 
| 96 | 
            +
                },
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                getContainer: function(options){
         | 
| 99 | 
            +
                  if(options.addMethod == 'after'){
         | 
| 100 | 
            +
                    if(!$(options.bind).next('#' + options.id).length){
         | 
| 101 | 
            +
                      $(options.bind)[options.addMethod]($('<div />', { id: options.id, class: options.containerClass }));
         | 
| 102 | 
            +
                    }
         | 
| 103 | 
            +
                    return $(options.bind).next('#' + options.id);
         | 
| 104 | 
            +
                  }else if(options.addMethod == 'before'){
         | 
| 105 | 
            +
                    if(!$(options.bind).prev('#' + options.id).length){
         | 
| 106 | 
            +
                      $(options.bind)[options.addMethod]($('<div />', { id: options.id, class: options.containerClass }));
         | 
| 107 | 
            +
                    }
         | 
| 108 | 
            +
                    return $(options.bind).prev('#' + options.id);
         | 
| 109 | 
            +
                  }else{
         | 
| 110 | 
            +
                    if(!$(options.bind).find('#' + options.id).length){
         | 
| 111 | 
            +
                      $(options.bind)[options.addMethod]($('<div />', { id: options.id, class: options.containerClass }));
         | 
| 112 | 
            +
                    }
         | 
| 113 | 
            +
                    return $(options.bind).find('#' + options.id);
         | 
| 114 | 
            +
                  }
         | 
| 115 | 
            +
                },
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                clear: function(o, options){
         | 
| 118 | 
            +
                  if(o && o.element){
         | 
| 119 | 
            +
                    // If o.element exists, it's the button that was clicked,
         | 
| 120 | 
            +
                    // in which case, remove the closest flash message
         | 
| 121 | 
            +
                    o.options = $.extend(_defaults, options);
         | 
| 122 | 
            +
                    $(o.element).closest('.flash')[o.options.concealMethod](o.options.concealTime, function(){
         | 
| 123 | 
            +
                      $(this).remove();
         | 
| 124 | 
            +
                      // If we removed the last flash message, also remove the container
         | 
| 125 | 
            +
                      if($('#' + o.options.id).find('.flash').length == 0){
         | 
| 126 | 
            +
                        $('#' + o.options.id).remove();
         | 
| 127 | 
            +
                      }
         | 
| 128 | 
            +
                    });
         | 
| 129 | 
            +
                  }else{
         | 
| 130 | 
            +
                    // .clear() was called preumably with no arguments,
         | 
| 131 | 
            +
                    // in which case hide and remove the entire flashes container element
         | 
| 132 | 
            +
                    options = $.extend(_defaults, options);
         | 
| 133 | 
            +
                    $('#' + options.id)[options.concealMethod](options.concealTime, function(){
         | 
| 134 | 
            +
                      $(this).remove();
         | 
| 135 | 
            +
                    });
         | 
| 136 | 
            +
                  }
         | 
| 137 | 
            +
                },
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                afterConfigChange: function(){
         | 
| 140 | 
            +
                  if(_defaults.autoClose && $('#' + _defaults.id + ' .flash').length){
         | 
| 141 | 
            +
                    var elements = $('#' + _defaults.id + ' .flash');
         | 
| 142 | 
            +
                    setTimeout(function(){
         | 
| 143 | 
            +
                      Voltron('Flash/clear', { element: elements });
         | 
| 144 | 
            +
                    }, _defaults.autoCloseAfter);
         | 
| 145 | 
            +
                  }
         | 
| 146 | 
            +
                }
         | 
| 147 | 
            +
              };
         | 
| 148 | 
            +
            }, true);
         | 
| @@ -0,0 +1,86 @@ | |
| 1 | 
            +
            $flash-red: #FCD7CF;
         | 
| 2 | 
            +
            $flash-green: #B1CEC4;
         | 
| 3 | 
            +
            $flash-yellow: #FFECC3;
         | 
| 4 | 
            +
            $flash-padding: 10px;
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            .flash {
         | 
| 7 | 
            +
              position: relative;
         | 
| 8 | 
            +
              width: 100%;
         | 
| 9 | 
            +
              padding: $flash-padding;
         | 
| 10 | 
            +
              padding-right: $flash-padding*4;
         | 
| 11 | 
            +
              -webkit-box-sizing: border-box;
         | 
| 12 | 
            +
              -moz-box-sizing: border-box;
         | 
| 13 | 
            +
              box-sizing: border-box;
         | 
| 14 | 
            +
              overflow: hidden;
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              &.alert {
         | 
| 17 | 
            +
                background-color: $flash-red;
         | 
| 18 | 
            +
                color: darken($flash-red, 70%);
         | 
| 19 | 
            +
                .flash-close:before, .flash-close:after {
         | 
| 20 | 
            +
                  background-color: darken($flash-red, 70%);
         | 
| 21 | 
            +
                }
         | 
| 22 | 
            +
              }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              &.warning {
         | 
| 25 | 
            +
                background-color: $flash-yellow;
         | 
| 26 | 
            +
                color: darken($flash-yellow, 70%);
         | 
| 27 | 
            +
                .flash-close:before, .flash-close:after {
         | 
| 28 | 
            +
                  background-color: darken($flash-yellow, 70%);
         | 
| 29 | 
            +
                }
         | 
| 30 | 
            +
              }
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              &.notice {
         | 
| 33 | 
            +
                background-color: $flash-green;
         | 
| 34 | 
            +
                color: darken($flash-green, 70%);
         | 
| 35 | 
            +
                .flash-close:before, .flash-close:after {
         | 
| 36 | 
            +
                  background-color: darken($flash-green, 70%);
         | 
| 37 | 
            +
                }
         | 
| 38 | 
            +
              }
         | 
| 39 | 
            +
            }
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            .flash-message {
         | 
| 42 | 
            +
              font-family: sans-serif;
         | 
| 43 | 
            +
              margin: 0;
         | 
| 44 | 
            +
              line-height: 22px;
         | 
| 45 | 
            +
              -webkit-box-sizing: border-box;
         | 
| 46 | 
            +
              -moz-box-sizing: border-box;
         | 
| 47 | 
            +
              box-sizing: border-box;
         | 
| 48 | 
            +
            }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            .flash-close {
         | 
| 51 | 
            +
              position: absolute;
         | 
| 52 | 
            +
              display: inline-block;
         | 
| 53 | 
            +
              width: $flash-padding*2;
         | 
| 54 | 
            +
              height: $flash-padding*2;
         | 
| 55 | 
            +
              overflow: hidden;
         | 
| 56 | 
            +
              background: none;
         | 
| 57 | 
            +
              border: 0;
         | 
| 58 | 
            +
              cursor: pointer;
         | 
| 59 | 
            +
              right: $flash-padding;
         | 
| 60 | 
            +
              top: $flash-padding;
         | 
| 61 | 
            +
              outline: none;
         | 
| 62 | 
            +
              &:before, &:after {
         | 
| 63 | 
            +
                content: '';
         | 
| 64 | 
            +
                position: absolute;
         | 
| 65 | 
            +
                width: 100%;
         | 
| 66 | 
            +
                height: 4px;
         | 
| 67 | 
            +
                top: 50%;
         | 
| 68 | 
            +
                left: 0;
         | 
| 69 | 
            +
                background: #000;
         | 
| 70 | 
            +
                margin-top: -1px;
         | 
| 71 | 
            +
              }
         | 
| 72 | 
            +
              &:before {
         | 
| 73 | 
            +
                -o-transform: rotate(45deg);
         | 
| 74 | 
            +
                -ms-transform: rotate(45deg);
         | 
| 75 | 
            +
                -moz-transform: rotate(45deg);
         | 
| 76 | 
            +
                -webkit-transform: rotate(45deg);
         | 
| 77 | 
            +
                transform: rotate(45deg);
         | 
| 78 | 
            +
              }
         | 
| 79 | 
            +
              &:after {
         | 
| 80 | 
            +
                -o-transform: rotate(-45deg);
         | 
| 81 | 
            +
                -ms-transform: rotate(-45deg);
         | 
| 82 | 
            +
                -moz-transform: rotate(-45deg);
         | 
| 83 | 
            +
                -webkit-transform: rotate(-45deg);
         | 
| 84 | 
            +
                transform: rotate(-45deg);
         | 
| 85 | 
            +
              }
         | 
| 86 | 
            +
            }
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            <% if flash.count > 0 %>
         | 
| 2 | 
            +
            <div id="flashes" class="<%= container_class %>">
         | 
| 3 | 
            +
            <% if Voltron.config.flash.group %>
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              <% flash.each do |type,messages| %>
         | 
| 6 | 
            +
              <div class="flash <%= type %>">
         | 
| 7 | 
            +
                <p class="flash-message"><%= Array.wrap(messages).join("<br />").html_safe %></p>
         | 
| 8 | 
            +
                <button class="flash-close" type="button" id="close-<%= type %>" data-dispatch="click"></button>
         | 
| 9 | 
            +
              </div>
         | 
| 10 | 
            +
              <% end %>
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            <% else %>
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              <% flash.each do |type,messages| %>
         | 
| 15 | 
            +
                <% Array.wrap(messages).each do |message| %>
         | 
| 16 | 
            +
                <div class="flash <%= type %>">
         | 
| 17 | 
            +
                  <p class="flash-message"><%= message.html_safe %></p>
         | 
| 18 | 
            +
                  <button class="flash-close" type="button" id="close-<%= type %>" data-dispatch="click"></button>
         | 
| 19 | 
            +
                </div>
         | 
| 20 | 
            +
                <% end %>
         | 
| 21 | 
            +
              <% end %>
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            <% end %>
         | 
| 24 | 
            +
            </div>
         | 
| 25 | 
            +
            <% end %>
         | 
| 26 | 
            +
            <% flash.clear %>
         | 
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bundler/setup"
         | 
| 4 | 
            +
            require "voltron/flash"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 7 | 
            +
            # with your gem easier. You can also use a different console, if you like.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 10 | 
            +
            # require "pry"
         | 
| 11 | 
            +
            # Pry.start
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            require "irb"
         | 
| 14 | 
            +
            IRB.start
         | 
    
        data/bin/setup
    ADDED
    
    
| @@ -0,0 +1,148 @@ | |
| 1 | 
            +
            //= require voltron
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Voltron.addModule('Flash', function(){
         | 
| 4 | 
            +
              var _defaults = {
         | 
| 5 | 
            +
                class: '',
         | 
| 6 | 
            +
                bind: 'body',
         | 
| 7 | 
            +
                id: 'flashes',
         | 
| 8 | 
            +
                containerClass: '',
         | 
| 9 | 
            +
                addMethod: 'prepend',
         | 
| 10 | 
            +
                revealMethod: 'slideDown',
         | 
| 11 | 
            +
                revealTime: 200,
         | 
| 12 | 
            +
                concealMethod: 'slideUp',
         | 
| 13 | 
            +
                concealTime: 200,
         | 
| 14 | 
            +
                autoClose: false,
         | 
| 15 | 
            +
                autoCloseAfter: 5000,
         | 
| 16 | 
            +
                autoAdd: true
         | 
| 17 | 
            +
              };
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              return {
         | 
| 20 | 
            +
                initialize: function(){
         | 
| 21 | 
            +
                  Voltron('Dispatch/addEventWatcher', 'click');
         | 
| 22 | 
            +
                  this.on('click:close-alert', 'click:close-notice', 'click:close-warning', this.clear);
         | 
| 23 | 
            +
                  this.addListener();
         | 
| 24 | 
            +
                },
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                setConfig: function(options){
         | 
| 27 | 
            +
                  _defaults = $.extend(_defaults, options);
         | 
| 28 | 
            +
                  this.afterConfigChange();
         | 
| 29 | 
            +
                  return this;
         | 
| 30 | 
            +
                },
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                addListener: function(){
         | 
| 33 | 
            +
                  $(document).ajaxComplete(function(event, request){
         | 
| 34 | 
            +
                    if(_defaults.autoAdd){
         | 
| 35 | 
            +
                      var flashes = request.getResponseHeader(Voltron.getConfig('flash/header', 'X-Flash'));
         | 
| 36 | 
            +
                      var flash = $.parseJSON(flashes);
         | 
| 37 | 
            +
                      if(flash){
         | 
| 38 | 
            +
                        Voltron('Flash/new', flash);
         | 
| 39 | 
            +
                      }
         | 
| 40 | 
            +
                    }
         | 
| 41 | 
            +
                  });
         | 
| 42 | 
            +
                },
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                new: function(flashes, options){
         | 
| 45 | 
            +
                  options = $.extend(_defaults, options);
         | 
| 46 | 
            +
                  var flash;
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  this.getContainer(options).addClass(options.class);
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  $.each(flashes, $.proxy(function(type, messages){
         | 
| 51 | 
            +
                    flash = this.addFlash(type, messages, options);
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    if(flash.find('.flash-message').length == 1){
         | 
| 54 | 
            +
                      // If this is the first flash message, reveal the whole container
         | 
| 55 | 
            +
                      flash.find('.flash-message').show();
         | 
| 56 | 
            +
                      flash[options.revealMethod](options.revealTime);
         | 
| 57 | 
            +
                    }else{
         | 
| 58 | 
            +
                      // Otherwise reveal just the newest message(s)
         | 
| 59 | 
            +
                      flash.find('.flash-message')[options.revealMethod](options.revealTime);
         | 
| 60 | 
            +
                    }
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    if(options.autoClose){
         | 
| 63 | 
            +
                      setTimeout(function(){
         | 
| 64 | 
            +
                        V('Flash/clear', { element: flash });
         | 
| 65 | 
            +
                      }, options.autoCloseAfter);
         | 
| 66 | 
            +
                    }
         | 
| 67 | 
            +
                  }, this));
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  return this;
         | 
| 70 | 
            +
                },
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                addFlash: function(type, messages, options){
         | 
| 73 | 
            +
                  var flash = this.getFlash(type);
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  flash.append($.map($.makeArray(messages), function(message){
         | 
| 76 | 
            +
                    return $('<p />', { class: 'flash-message' }).html(message).hide();
         | 
| 77 | 
            +
                  }));
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  if(!Voltron.getConfig('flash/group') || !flash.find('.flash-close').length){
         | 
| 80 | 
            +
                    flash.append($('<button />', { class: 'flash-close', type: 'button', id: 'close-' + type, 'data-dispatch': 'click' }));
         | 
| 81 | 
            +
                  }
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  if(!this.getContainer(options).length){
         | 
| 84 | 
            +
                    Voltron.debug('warn', 'Element with which to bind flash messages to could not be found. The bind selector given was %o. Please ensure an element matching the given selector exists.', options.bind);
         | 
| 85 | 
            +
                  }
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  this.getContainer(options).append(flash);
         | 
| 88 | 
            +
                  return flash;
         | 
| 89 | 
            +
                },
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                getFlash: function(type){
         | 
| 92 | 
            +
                  if(Voltron.getConfig('flash/group') && $('.flash.' + type).length){
         | 
| 93 | 
            +
                    return $('.flash.' + type).first();
         | 
| 94 | 
            +
                  }
         | 
| 95 | 
            +
                  return $('<div />', { class: ['flash', type].join(' ') }).hide();
         | 
| 96 | 
            +
                },
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                getContainer: function(options){
         | 
| 99 | 
            +
                  if(options.addMethod == 'after'){
         | 
| 100 | 
            +
                    if(!$(options.bind).next('#' + options.id).length){
         | 
| 101 | 
            +
                      $(options.bind)[options.addMethod]($('<div />', { id: options.id, class: options.containerClass }));
         | 
| 102 | 
            +
                    }
         | 
| 103 | 
            +
                    return $(options.bind).next('#' + options.id);
         | 
| 104 | 
            +
                  }else if(options.addMethod == 'before'){
         | 
| 105 | 
            +
                    if(!$(options.bind).prev('#' + options.id).length){
         | 
| 106 | 
            +
                      $(options.bind)[options.addMethod]($('<div />', { id: options.id, class: options.containerClass }));
         | 
| 107 | 
            +
                    }
         | 
| 108 | 
            +
                    return $(options.bind).prev('#' + options.id);
         | 
| 109 | 
            +
                  }else{
         | 
| 110 | 
            +
                    if(!$(options.bind).find('#' + options.id).length){
         | 
| 111 | 
            +
                      $(options.bind)[options.addMethod]($('<div />', { id: options.id, class: options.containerClass }));
         | 
| 112 | 
            +
                    }
         | 
| 113 | 
            +
                    return $(options.bind).find('#' + options.id);
         | 
| 114 | 
            +
                  }
         | 
| 115 | 
            +
                },
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                clear: function(o, options){
         | 
| 118 | 
            +
                  if(o && o.element){
         | 
| 119 | 
            +
                    // If o.element exists, it's the button that was clicked,
         | 
| 120 | 
            +
                    // in which case, remove the closest flash message
         | 
| 121 | 
            +
                    o.options = $.extend(_defaults, options);
         | 
| 122 | 
            +
                    $(o.element).closest('.flash')[o.options.concealMethod](o.options.concealTime, function(){
         | 
| 123 | 
            +
                      $(this).remove();
         | 
| 124 | 
            +
                      // If we removed the last flash message, also remove the container
         | 
| 125 | 
            +
                      if($('#' + o.options.id).find('.flash').length == 0){
         | 
| 126 | 
            +
                        $('#' + o.options.id).remove();
         | 
| 127 | 
            +
                      }
         | 
| 128 | 
            +
                    });
         | 
| 129 | 
            +
                  }else{
         | 
| 130 | 
            +
                    // .clear() was called preumably with no arguments,
         | 
| 131 | 
            +
                    // in which case hide and remove the entire flashes container element
         | 
| 132 | 
            +
                    options = $.extend(_defaults, options);
         | 
| 133 | 
            +
                    $('#' + options.id)[options.concealMethod](options.concealTime, function(){
         | 
| 134 | 
            +
                      $(this).remove();
         | 
| 135 | 
            +
                    });
         | 
| 136 | 
            +
                  }
         | 
| 137 | 
            +
                },
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                afterConfigChange: function(){
         | 
| 140 | 
            +
                  if(_defaults.autoClose && $('#' + _defaults.id + ' .flash').length){
         | 
| 141 | 
            +
                    var elements = $('#' + _defaults.id + ' .flash');
         | 
| 142 | 
            +
                    setTimeout(function(){
         | 
| 143 | 
            +
                      Voltron('Flash/clear', { element: elements });
         | 
| 144 | 
            +
                    }, _defaults.autoCloseAfter);
         | 
| 145 | 
            +
                  }
         | 
| 146 | 
            +
                }
         | 
| 147 | 
            +
              };
         | 
| 148 | 
            +
            }, true);
         | 
| @@ -0,0 +1,86 @@ | |
| 1 | 
            +
            $flash-red: #FCD7CF;
         | 
| 2 | 
            +
            $flash-green: #B1CEC4;
         | 
| 3 | 
            +
            $flash-yellow: #FFECC3;
         | 
| 4 | 
            +
            $flash-padding: 10px;
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            .flash {
         | 
| 7 | 
            +
              position: relative;
         | 
| 8 | 
            +
              width: 100%;
         | 
| 9 | 
            +
              padding: $flash-padding;
         | 
| 10 | 
            +
              padding-right: $flash-padding*4;
         | 
| 11 | 
            +
              -webkit-box-sizing: border-box;
         | 
| 12 | 
            +
              -moz-box-sizing: border-box;
         | 
| 13 | 
            +
              box-sizing: border-box;
         | 
| 14 | 
            +
              overflow: hidden;
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              &.alert {
         | 
| 17 | 
            +
                background-color: $flash-red;
         | 
| 18 | 
            +
                color: darken($flash-red, 70%);
         | 
| 19 | 
            +
                .flash-close:before, .flash-close:after {
         | 
| 20 | 
            +
                  background-color: darken($flash-red, 70%);
         | 
| 21 | 
            +
                }
         | 
| 22 | 
            +
              }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              &.warning {
         | 
| 25 | 
            +
                background-color: $flash-yellow;
         | 
| 26 | 
            +
                color: darken($flash-yellow, 70%);
         | 
| 27 | 
            +
                .flash-close:before, .flash-close:after {
         | 
| 28 | 
            +
                  background-color: darken($flash-yellow, 70%);
         | 
| 29 | 
            +
                }
         | 
| 30 | 
            +
              }
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              &.notice {
         | 
| 33 | 
            +
                background-color: $flash-green;
         | 
| 34 | 
            +
                color: darken($flash-green, 70%);
         | 
| 35 | 
            +
                .flash-close:before, .flash-close:after {
         | 
| 36 | 
            +
                  background-color: darken($flash-green, 70%);
         | 
| 37 | 
            +
                }
         | 
| 38 | 
            +
              }
         | 
| 39 | 
            +
            }
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            .flash-message {
         | 
| 42 | 
            +
              font-family: sans-serif;
         | 
| 43 | 
            +
              margin: 0;
         | 
| 44 | 
            +
              line-height: 22px;
         | 
| 45 | 
            +
              -webkit-box-sizing: border-box;
         | 
| 46 | 
            +
              -moz-box-sizing: border-box;
         | 
| 47 | 
            +
              box-sizing: border-box;
         | 
| 48 | 
            +
            }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            .flash-close {
         | 
| 51 | 
            +
              position: absolute;
         | 
| 52 | 
            +
              display: inline-block;
         | 
| 53 | 
            +
              width: $flash-padding*2;
         | 
| 54 | 
            +
              height: $flash-padding*2;
         | 
| 55 | 
            +
              overflow: hidden;
         | 
| 56 | 
            +
              background: none;
         | 
| 57 | 
            +
              border: 0;
         | 
| 58 | 
            +
              cursor: pointer;
         | 
| 59 | 
            +
              right: $flash-padding;
         | 
| 60 | 
            +
              top: $flash-padding;
         | 
| 61 | 
            +
              outline: none;
         | 
| 62 | 
            +
              &:before, &:after {
         | 
| 63 | 
            +
                content: '';
         | 
| 64 | 
            +
                position: absolute;
         | 
| 65 | 
            +
                width: 100%;
         | 
| 66 | 
            +
                height: 4px;
         | 
| 67 | 
            +
                top: 50%;
         | 
| 68 | 
            +
                left: 0;
         | 
| 69 | 
            +
                background: #000;
         | 
| 70 | 
            +
                margin-top: -1px;
         | 
| 71 | 
            +
              }
         | 
| 72 | 
            +
              &:before {
         | 
| 73 | 
            +
                -o-transform: rotate(45deg);
         | 
| 74 | 
            +
                -ms-transform: rotate(45deg);
         | 
| 75 | 
            +
                -moz-transform: rotate(45deg);
         | 
| 76 | 
            +
                -webkit-transform: rotate(45deg);
         | 
| 77 | 
            +
                transform: rotate(45deg);
         | 
| 78 | 
            +
              }
         | 
| 79 | 
            +
              &:after {
         | 
| 80 | 
            +
                -o-transform: rotate(-45deg);
         | 
| 81 | 
            +
                -ms-transform: rotate(-45deg);
         | 
| 82 | 
            +
                -moz-transform: rotate(-45deg);
         | 
| 83 | 
            +
                -webkit-transform: rotate(-45deg);
         | 
| 84 | 
            +
                transform: rotate(-45deg);
         | 
| 85 | 
            +
              }
         | 
| 86 | 
            +
            }
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            <% if flash.count > 0 %>
         | 
| 2 | 
            +
            <div id="flashes" class="<%= container_class %>">
         | 
| 3 | 
            +
            <% if Voltron.config.flash.group %>
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              <% flash.each do |type,messages| %>
         | 
| 6 | 
            +
              <div class="flash <%= type %>">
         | 
| 7 | 
            +
                <p class="flash-message"><%= Array.wrap(messages).join("<br />").html_safe %></p>
         | 
| 8 | 
            +
                <button class="flash-close" type="button" id="close-<%= type %>" data-dispatch="click"></button>
         | 
| 9 | 
            +
              </div>
         | 
| 10 | 
            +
              <% end %>
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            <% else %>
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              <% flash.each do |type,messages| %>
         | 
| 15 | 
            +
                <% Array.wrap(messages).each do |message| %>
         | 
| 16 | 
            +
                <div class="flash <%= type %>">
         | 
| 17 | 
            +
                  <p class="flash-message"><%= message.html_safe %></p>
         | 
| 18 | 
            +
                  <button class="flash-close" type="button" id="close-<%= type %>" data-dispatch="click"></button>
         | 
| 19 | 
            +
                </div>
         | 
| 20 | 
            +
                <% end %>
         | 
| 21 | 
            +
              <% end %>
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            <% end %>
         | 
| 24 | 
            +
            </div>
         | 
| 25 | 
            +
            <% end %>
         | 
| 26 | 
            +
            <% flash.clear %>
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            module Voltron
         | 
| 2 | 
            +
              module Flash
         | 
| 3 | 
            +
                module Generators
         | 
| 4 | 
            +
                  module Install
         | 
| 5 | 
            +
                    class AssetsGenerator < Rails::Generators::Base
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                      source_root File.expand_path("../../../../templates", __FILE__)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                      desc "Install Voltron Flash assets"
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                      def copy_javascripts_assets
         | 
| 12 | 
            +
                        copy_file "app/assets/javascripts/voltron-flash.js", Rails.root.join("app", "assets", "javascripts", "voltron-flash.js")
         | 
| 13 | 
            +
                      end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                      def copy_stylesheets_assets
         | 
| 16 | 
            +
                        copy_file "app/assets/stylesheets/voltron-flash.scss", Rails.root.join("app", "assets", "stylesheets", "voltron-flash.scss")
         | 
| 17 | 
            +
                      end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                      def copy_views
         | 
| 20 | 
            +
                        copy_file "app/views/voltron/flash.html.erb", Rails.root.join("app", "views", "voltron", "flash.html.erb")
         | 
| 21 | 
            +
                      end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            module Voltron
         | 
| 2 | 
            +
              module Flash
         | 
| 3 | 
            +
                module Generators
         | 
| 4 | 
            +
                  class InstallGenerator < Rails::Generators::Base
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                    source_root File.expand_path("../../../templates", __FILE__)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    desc "Add Voltron Flash initializer"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    def inject_initializer
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                      voltron_initialzer_path = Rails.root.join("config", "initializers", "voltron.rb")
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                      unless File.exist? voltron_initialzer_path
         | 
| 15 | 
            +
                        unless system("cd #{Rails.root.to_s} && rails generate voltron:install")
         | 
| 16 | 
            +
                          puts "Voltron initializer does not exist. Please ensure you have the 'voltron' gem installed and run `rails g voltron:install` to create it"
         | 
| 17 | 
            +
                          return false
         | 
| 18 | 
            +
                        end
         | 
| 19 | 
            +
                      end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                      current_initiailzer = File.read voltron_initialzer_path
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                      unless current_initiailzer.match(Regexp.new(/# === Voltron Flash Configuration ===/))
         | 
| 24 | 
            +
                        inject_into_file(voltron_initialzer_path, after: "Voltron.setup do |config|\n") do
         | 
| 25 | 
            +
            <<-CONTENT
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              # === Voltron Flash Configuration ===
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              # What http header the flash messages should be added to on ajax responses
         | 
| 30 | 
            +
              config.flash.header = "X-Flash"
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              # Whether to group flash messages by type, or give each flash message it's own line, complete with close icon
         | 
| 33 | 
            +
              config.flash.group = true
         | 
| 34 | 
            +
            CONTENT
         | 
| 35 | 
            +
                        end
         | 
| 36 | 
            +
                      end
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require "active_support"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Voltron
         | 
| 4 | 
            +
              class Config
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                include ::ActiveSupport::Callbacks
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                set_callback :generate_voltron_config, :add_flash_config
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def flash
         | 
| 11 | 
            +
                  @flash ||= Flash.new
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def add_flash_config
         | 
| 15 | 
            +
                  Voltron.config.merge(flash: flash.to_h)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                class Flash
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  attr_accessor :header, :group
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def initialize
         | 
| 23 | 
            +
                    @header ||= "X-Flash"
         | 
| 24 | 
            +
                    @group ||= true
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  def to_h
         | 
| 28 | 
            +
                    { header: header, group: group }
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,55 @@ | |
| 1 | 
            +
            require "voltron"
         | 
| 2 | 
            +
            require "voltron/flash/version"
         | 
| 3 | 
            +
            require "voltron/config/flash"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Voltron
         | 
| 6 | 
            +
              module Flash
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def self.prepended(base)
         | 
| 9 | 
            +
                  base.send :after_action, :include_flash_later
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def render(*args)
         | 
| 13 | 
            +
                  include_flash_now
         | 
| 14 | 
            +
                  super *args
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def flash!(**flashes)
         | 
| 18 | 
            +
                  flashes.symbolize_keys.each do |type,messages|
         | 
| 19 | 
            +
                    stored_flashes[type] ||= []
         | 
| 20 | 
            +
                    stored_flashes[type] += Array.wrap(messages)
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def stored_flashes
         | 
| 27 | 
            +
                    @stored_flashes ||= {}
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  # Before rendering, include any flash messages in flash.now,
         | 
| 31 | 
            +
                  # so they will be available when the page is rendered
         | 
| 32 | 
            +
                  def include_flash_now
         | 
| 33 | 
            +
                    if !request.xhr?
         | 
| 34 | 
            +
                      stored_flashes.each { |type,messages| flash.now[type] = messages }
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  # If request is an ajax request, or we are redirecting, include flash messages
         | 
| 39 | 
            +
                  # in the appropriate outlet, either response headers or `flash` itself
         | 
| 40 | 
            +
                  def include_flash_later
         | 
| 41 | 
            +
                    if request.xhr?
         | 
| 42 | 
            +
                      response.headers[Voltron.config.flash.header] = stored_flashes.to_json
         | 
| 43 | 
            +
                    elsif is_redirecting?
         | 
| 44 | 
            +
                      stored_flashes.each { |type,messages| flash[type] = messages }
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def is_redirecting?
         | 
| 49 | 
            +
                    self.status == 302 || self.status == 301
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            require "voltron/flash/engine" if defined?(Rails)
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            module Voltron
         | 
| 2 | 
            +
              module Flash
         | 
| 3 | 
            +
                class Engine < Rails::Engine
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                  isolate_namespace Voltron
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  config.autoload_paths += Dir["#{config.root}/lib/**/"]
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  initializer "voltron.flash.initialize" do
         | 
| 10 | 
            +
                    ::ActionController::Base.send :prepend, ::Voltron::Flash
         | 
| 11 | 
            +
                    ::ActionController::Base.send :helper, ::Voltron::FlashHelper
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'voltron/flash/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "voltron-flash"
         | 
| 8 | 
            +
              spec.version       = Voltron::Flash::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Eric Hainer"]
         | 
| 10 | 
            +
              spec.email         = ["eric@commercekitchen.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = %q{Voltron library to more easily deal with flash messages}
         | 
| 13 | 
            +
              spec.homepage      = "https://github.com/ehainer/voltron-flash"
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 17 | 
            +
              spec.bindir        = "exe"
         | 
| 18 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_dependency "rails", ">= 4.2"
         | 
| 22 | 
            +
              spec.add_dependency "voltron", ">= 0.1.9"
         | 
| 23 | 
            +
              spec.add_dependency "sass-rails", ">= 5.0.0"
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              spec.add_development_dependency "byebug"
         | 
| 26 | 
            +
              spec.add_development_dependency "bundler", "~> 1.12"
         | 
| 27 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 28 | 
            +
              spec.add_development_dependency "rspec", "~> 3.0"
         | 
| 29 | 
            +
              spec.add_development_dependency "rspec-rails", ">= 3.4"
         | 
| 30 | 
            +
              spec.add_development_dependency "sqlite3", ">= 1.2"
         | 
| 31 | 
            +
              spec.add_development_dependency "simplecov", "0.11.0"
         | 
| 32 | 
            +
              spec.add_development_dependency "jquery-rails", "~> 4.2.0"
         | 
| 33 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,222 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: voltron-flash
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Eric Hainer
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2016-12-12 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rails
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '4.2'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '4.2'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: voltron
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 0.1.9
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 0.1.9
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: sass-rails
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: 5.0.0
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 5.0.0
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: byebug
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: bundler
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '1.12'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '1.12'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: rake
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '10.0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '10.0'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: rspec
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - "~>"
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '3.0'
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - "~>"
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '3.0'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: rspec-rails
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ">="
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '3.4'
         | 
| 118 | 
            +
              type: :development
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - ">="
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '3.4'
         | 
| 125 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 126 | 
            +
              name: sqlite3
         | 
| 127 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 | 
            +
                requirements:
         | 
| 129 | 
            +
                - - ">="
         | 
| 130 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            +
                    version: '1.2'
         | 
| 132 | 
            +
              type: :development
         | 
| 133 | 
            +
              prerelease: false
         | 
| 134 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 | 
            +
                requirements:
         | 
| 136 | 
            +
                - - ">="
         | 
| 137 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            +
                    version: '1.2'
         | 
| 139 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            +
              name: simplecov
         | 
| 141 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - '='
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: 0.11.0
         | 
| 146 | 
            +
              type: :development
         | 
| 147 | 
            +
              prerelease: false
         | 
| 148 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
                requirements:
         | 
| 150 | 
            +
                - - '='
         | 
| 151 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                    version: 0.11.0
         | 
| 153 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 154 | 
            +
              name: jquery-rails
         | 
| 155 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 156 | 
            +
                requirements:
         | 
| 157 | 
            +
                - - "~>"
         | 
| 158 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 159 | 
            +
                    version: 4.2.0
         | 
| 160 | 
            +
              type: :development
         | 
| 161 | 
            +
              prerelease: false
         | 
| 162 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 163 | 
            +
                requirements:
         | 
| 164 | 
            +
                - - "~>"
         | 
| 165 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 166 | 
            +
                    version: 4.2.0
         | 
| 167 | 
            +
            description: 
         | 
| 168 | 
            +
            email:
         | 
| 169 | 
            +
            - eric@commercekitchen.com
         | 
| 170 | 
            +
            executables: []
         | 
| 171 | 
            +
            extensions: []
         | 
| 172 | 
            +
            extra_rdoc_files: []
         | 
| 173 | 
            +
            files:
         | 
| 174 | 
            +
            - ".gitignore"
         | 
| 175 | 
            +
            - ".rspec"
         | 
| 176 | 
            +
            - ".travis.yml"
         | 
| 177 | 
            +
            - CODE_OF_CONDUCT.md
         | 
| 178 | 
            +
            - Gemfile
         | 
| 179 | 
            +
            - LICENSE.txt
         | 
| 180 | 
            +
            - README.md
         | 
| 181 | 
            +
            - Rakefile
         | 
| 182 | 
            +
            - app/assets/javascripts/voltron-flash.js
         | 
| 183 | 
            +
            - app/assets/stylesheets/voltron-flash.scss
         | 
| 184 | 
            +
            - app/helpers/voltron/flash_helper.rb
         | 
| 185 | 
            +
            - app/views/voltron/flash.html.erb
         | 
| 186 | 
            +
            - bin/console
         | 
| 187 | 
            +
            - bin/setup
         | 
| 188 | 
            +
            - lib/generators/templates/app/assets/javascripts/voltron-flash.js
         | 
| 189 | 
            +
            - lib/generators/templates/app/assets/stylesheets/voltron-flash.scss
         | 
| 190 | 
            +
            - lib/generators/templates/app/views/voltron/flash.html.erb
         | 
| 191 | 
            +
            - lib/generators/voltron/flash/install/assets_generator.rb
         | 
| 192 | 
            +
            - lib/generators/voltron/flash/install_generator.rb
         | 
| 193 | 
            +
            - lib/voltron/config/flash.rb
         | 
| 194 | 
            +
            - lib/voltron/flash.rb
         | 
| 195 | 
            +
            - lib/voltron/flash/engine.rb
         | 
| 196 | 
            +
            - lib/voltron/flash/version.rb
         | 
| 197 | 
            +
            - voltron-flash.gemspec
         | 
| 198 | 
            +
            homepage: https://github.com/ehainer/voltron-flash
         | 
| 199 | 
            +
            licenses:
         | 
| 200 | 
            +
            - MIT
         | 
| 201 | 
            +
            metadata: {}
         | 
| 202 | 
            +
            post_install_message: 
         | 
| 203 | 
            +
            rdoc_options: []
         | 
| 204 | 
            +
            require_paths:
         | 
| 205 | 
            +
            - lib
         | 
| 206 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 207 | 
            +
              requirements:
         | 
| 208 | 
            +
              - - ">="
         | 
| 209 | 
            +
                - !ruby/object:Gem::Version
         | 
| 210 | 
            +
                  version: '0'
         | 
| 211 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 212 | 
            +
              requirements:
         | 
| 213 | 
            +
              - - ">="
         | 
| 214 | 
            +
                - !ruby/object:Gem::Version
         | 
| 215 | 
            +
                  version: '0'
         | 
| 216 | 
            +
            requirements: []
         | 
| 217 | 
            +
            rubyforge_project: 
         | 
| 218 | 
            +
            rubygems_version: 2.5.1
         | 
| 219 | 
            +
            signing_key: 
         | 
| 220 | 
            +
            specification_version: 4
         | 
| 221 | 
            +
            summary: Voltron library to more easily deal with flash messages
         | 
| 222 | 
            +
            test_files: []
         |