rails_live 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/rails_live_manifest.js +2 -0
  6. data/app/assets/images/rails_live/favicon.ico +0 -0
  7. data/app/assets/images/rails_live/github1.svg +1 -0
  8. data/app/assets/images/rails_live/loading.gif +0 -0
  9. data/app/assets/images/rails_live/record1.png +0 -0
  10. data/app/assets/images/rails_live/record1.svg +1 -0
  11. data/app/assets/images/rails_live/record2.png +0 -0
  12. data/app/assets/images/rails_live/record2.svg +1 -0
  13. data/app/assets/images/rails_live/record3.png +0 -0
  14. data/app/assets/images/rails_live/record3.svg +1 -0
  15. data/app/assets/javascripts/cable.js +13 -0
  16. data/app/assets/javascripts/channels/rails_live/updates.coffee +43 -0
  17. data/app/assets/javascripts/rails_live/app.js +26 -0
  18. data/app/assets/javascripts/rails_live/application.js +7 -0
  19. data/app/assets/javascripts/rails_live/mustache.js +682 -0
  20. data/app/assets/javascripts/rails_live/mustache.min.js +1 -0
  21. data/app/assets/stylesheets/rails_live/animate.css +3623 -0
  22. data/app/assets/stylesheets/rails_live/application.css +9 -0
  23. data/app/assets/stylesheets/rails_live/bulma.min.css +1 -0
  24. data/app/assets/stylesheets/rails_live/header.css +12 -0
  25. data/app/assets/stylesheets/rails_live/layout.css +3 -0
  26. data/app/assets/stylesheets/rails_live/messages.scss +15 -0
  27. data/app/channels/application_cable/channel.rb +4 -0
  28. data/app/channels/application_cable/connection.rb +4 -0
  29. data/app/channels/channel.rb +2 -0
  30. data/app/channels/rails_live/updates_channel.rb +10 -0
  31. data/app/controllers/rails_live/application_controller.rb +5 -0
  32. data/app/controllers/rails_live/stream_controller.rb +8 -0
  33. data/app/helpers/rails_live/application_helper.rb +4 -0
  34. data/app/jobs/rails_live/application_job.rb +4 -0
  35. data/app/mailers/rails_live/application_mailer.rb +6 -0
  36. data/app/models/rails_live/application_record.rb +5 -0
  37. data/app/views/layouts/rails_live/application.html.erb +27 -0
  38. data/app/views/rails_live/shared/_header.html.erb +29 -0
  39. data/app/views/rails_live/stream/index.html.erb +19 -0
  40. data/config/routes.rb +4 -0
  41. data/lib/rails_live.rb +14 -0
  42. data/lib/rails_live/engine.rb +11 -0
  43. data/lib/rails_live/railtie.rb +4 -0
  44. data/lib/rails_live/version.rb +3 -0
  45. data/lib/tasks/rails_live_tasks.rake +4 -0
  46. metadata +214 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 80cece85418243f9babcb5c0be860643d0d0b86e9aec537b3f8d35ddc44391c3
4
+ data.tar.gz: 0fda7ac95f1a6ff4d61e05eb4eeaaf9fad8370899add9c630e3b37a64b71a5b2
5
+ SHA512:
6
+ metadata.gz: a2f6dd3b7831d32a784bd040583494cc6149a1d9b83f77cefee24689075fe7feef00414b12f2e8f0ab4b29487a26b4b991d46cff876a02efd4859c382418df28
7
+ data.tar.gz: 6684f12b692e9c4d384813e42f2873033722e2a2f6e2c5c2512b3ca3044547d275c6e8f3912242903f4d57e130135aa8c8377ec736a7ee173ef4916bcffcf4ff
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Igor Kasyanchuk
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # RailsLive
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rails_live'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install rails_live
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsLive'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/rails_live .js
2
+ //= link_directory ../stylesheets/rails_live .css
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="github"><path d="M254.5,16.5c-131.996,0-239,107.004-239,239s107.004,239,239,239s239-107.004,239-239S386.496,16.5,254.5,16.5z M412.892,413.892C370.584,456.2,314.333,479.5,254.5,479.5c-59.833,0-116.084-23.3-158.392-65.608 C53.8,371.584,30.5,315.333,30.5,255.5c0-59.833,23.3-116.084,65.608-158.392C138.416,54.8,194.667,31.5,254.5,31.5 c59.833,0,116.084,23.3,158.392,65.608C455.2,139.416,478.5,195.667,478.5,255.5C478.5,315.333,455.2,371.584,412.892,413.892z"/><path d="M254,118.205c-75.969,0-137.563,61.594-137.563,137.563c0,60.788,39.412,112.341,94.079,130.527 c6.877,1.26,9.387-2.989,9.387-6.616c0-3.275-0.126-14.122-0.193-25.608c-38.253,8.312-46.339-16.221-46.339-16.221 c-6.263-15.886-15.273-20.117-15.273-20.117c-12.502-8.53,0.948-8.363,0.948-8.363c13.812,0.957,21.083,14.173,21.083,14.173 c12.275,21.024,32.208,14.945,40.033,11.419c1.25-8.866,4.81-14.945,8.732-18.371c-30.537-3.476-62.66-15.281-62.66-67.992 c0-15.029,5.365-27.287,14.147-36.918c-1.402-3.493-6.138-17.489,1.36-36.422c0,0,11.536-3.694,37.833,14.106 c10.965-3.065,22.728-4.576,34.424-4.626c11.687,0.051,23.459,1.578,34.441,4.643c26.247-17.817,37.8-14.106,37.8-14.106 c7.523,18.95,2.788,32.93,1.377,36.406c8.816,9.63,14.139,21.889,14.139,36.918c0,52.846-32.174,64.483-62.82,67.892 c4.954,4.265,9.337,12.628,9.337,25.457c0,18.388-0.185,33.215-0.185,37.749c0,3.661,2.502,7.943,9.471,6.599 c54.626-18.22,94.004-69.772,94.004-130.527C391.563,179.799,329.969,118.205,254,118.205z"/></g></svg>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><svg height="48px" id="svg1307" width="48px" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs id="defs1309"><linearGradient id="linearGradient3837"><stop id="stop3839" offset="0" style="stop-color:#000000;stop-opacity:1;"/><stop id="stop3841" offset="1" style="stop-color:#ffffff;stop-opacity:0.78350514;"/></linearGradient><linearGradient id="linearGradient2257"><stop id="stop2259" offset="0" style="stop-color:#ef2929"/><stop id="stop2261" offset="1" style="stop-color:#cc0000"/></linearGradient><linearGradient id="linearGradient3340"><stop id="stop3342" offset="0" style="stop-color:#ffffff;stop-opacity:1;"/><stop id="stop3344" offset="1" style="stop-color:#ffffff;stop-opacity:0;"/></linearGradient><linearGradient id="linearGradient8662"><stop id="stop8664" offset="0" style="stop-color:#000000;stop-opacity:1;"/><stop id="stop8666" offset="1" style="stop-color:#000000;stop-opacity:0;"/></linearGradient><radialGradient cx="24.837126" cy="36.421127" fx="24.837126" fy="36.421127" gradientTransform="matrix(1,0,0,0.536723,-3.241652e-13,16.87306)" gradientUnits="userSpaceOnUse" id="radialGradient2228" r="15.644737" xlink:href="#linearGradient8662"/><radialGradient cx="21.929186" cy="-3.2182934" fx="21.929186" fy="-3.2182934" gradientTransform="matrix(3.658819,-3.13388e-16,1.719536e-16,2.080782,-62.4164,12.76204)" gradientUnits="userSpaceOnUse" id="radialGradient1368" r="13" xlink:href="#linearGradient3340"/><radialGradient cx="22.5" cy="28.116049" fx="22.5" fy="28.116049" gradientTransform="matrix(2.365562,-4.942242e-16,5.359766e-16,2.202845,-30.72517,-34.23996)" gradientUnits="userSpaceOnUse" id="radialGradient2263" r="14.537862" xlink:href="#linearGradient2257"/><linearGradient gradientUnits="userSpaceOnUse" id="linearGradient3843" x1="21.702389" x2="21.816015" xlink:href="#linearGradient3837" y1="8.9115314" y2="35.546108"/><radialGradient cx="22.5" cy="28.116049" fx="22.5" fy="28.116049" gradientTransform="matrix(2.365562,-4.942242e-16,5.359766e-16,2.202845,-30.72517,-34.23996)" gradientUnits="userSpaceOnUse" id="radialGradient3845" r="14.537862" xlink:href="#linearGradient2257"/></defs><g id="layer1" style="display:inline"><path d="M 36.5 22 A 14 13 0 1 1 8.5,22 A 14 13 0 1 1 36.5 22 z" id="path3835" style="opacity:0.15;color:#000000;fill:url(#radialGradient3845);fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient3843);stroke-width:3.13661647;stroke-linecap:square;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" transform="matrix(0.920697,0,0,0.99358,3.679484,1.641236)"/><path d="M 40.481863 36.421127 A 15.644737 8.3968935 0 1 1 9.1923885,36.421127 A 15.644737 8.3968935 0 1 1 40.481863 36.421127 z" id="path2226" style="opacity:0.03999999;color:#000000;fill:url(#radialGradient2228);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:10;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" transform="matrix(1.150533,0,0,0.565685,-4.5765,16.55285)"/><path d="M 36.5 22 A 14 13 0 1 1 8.5,22 A 14 13 0 1 1 36.5 22 z" id="path2525" style="color:#000000;fill:url(#radialGradient2263);fill-opacity:1.0;fill-rule:evenodd;stroke:#cc0000;stroke-width:1.0757246;stroke-linecap:square;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" transform="matrix(0.894862,0,0,0.9657,3.855776,2.660348)"/><path d="M 38 24 A 14 14 0 1 1 10,24 A 14 14 0 1 1 38 24 z" id="path2527" style="color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#f77d7d;stroke-width:1.21739173;stroke-linecap:square;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" transform="matrix(0.821429,0,0,0.821429,4.285117,4.191455)"/><path d="M 23.84315,11.90574 C 17.563618,11.985335 12.438727,16.897799 12.03065,23.09324 C 18.148473,25.61002 25.90107,21.642017 35.172655,19.711354 C 34.484245,16.962785 30.617935,11.90574 23.9994,11.90574 C 23.947693,11.90574 23.894703,11.905087 23.84315,11.90574 z " id="path2529" style="opacity:0.6;fill:url(#radialGradient1368);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.25pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline"/></g></svg>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><svg style="enable-background:new 0 0 48 48;" version="1.1" viewBox="0 0 48 48" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Icons"><g><path d="M30.57464,25.95474v4.25556c0,1.17925-0.96135,2.12778-2.12778,2.12778H11.2708 c-1.16643,0-2.11496-0.94853-2.11496-2.12778V17.7897c0-1.17925,0.94853-2.12778,2.11496-2.12778h17.17606 c1.16643,0,2.12778,0.94853,2.12778,2.12778v4.2812" style="fill:#F4F4F4;"/><linearGradient gradientUnits="userSpaceOnUse" id="SVGID_1_" x1="34.7094" x2="34.7094" y1="31.17346" y2="15.0741"><stop offset="0.09694" style="stop-color:#FFD879"/><stop offset="0.15387" style="stop-color:#FCCB76"/><stop offset="0.25828" style="stop-color:#F5AA6C"/><stop offset="0.39756" style="stop-color:#E9755E"/><stop offset="0.44898" style="stop-color:#E45F58"/><stop offset="0.67857" style="stop-color:#D22A9C"/><stop offset="1" style="stop-color:#6968DF"/></linearGradient><path d="M30.57464,26.07546V22.0709l4.62985-3.53602 c0.16327-0.11661,0.28138-0.15711,0.47364-0.15711H38.011c0.46144,0,0.83316,0.37172,0.83316,0.83317v2.1406v5.30663v2.12778 c0,0.46145-0.37172,0.83317-0.83316,0.83317h-2.33287c-0.19227,0-0.3103-0.03481-0.4999-0.17945l-4.60359-3.48492" style="fill:url(#SVGID_1_);"/><path d=" M30.57464,25.95474v4.25556c0,1.17925-0.96135,2.12778-2.12778,2.12778H11.2708c-1.16643,0-2.11496-0.94853-2.11496-2.12778 V17.7897c0-1.17925,0.94853-2.12778,2.11496-2.12778h17.17606c1.16643,0,2.12778,0.94853,2.12778,2.12778v4.2812" style="fill:none;stroke:#303030;stroke-width:0.7;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/><path d=" M30.57464,26.07546V22.0709l4.62985-3.53602c0.16327-0.11661,0.28138-0.15711,0.47364-0.15711H38.011 c0.46144,0,0.83316,0.37172,0.83316,0.83317v2.1406v5.30663v2.12778c0,0.46145-0.37172,0.83317-0.83316,0.83317h-2.33287 c-0.19227,0-0.3103-0.03481-0.4999-0.17945l-4.60359-3.48492" style="fill:none;stroke:#303030;stroke-width:0.7;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/><linearGradient gradientUnits="userSpaceOnUse" id="SVGID_2_" x1="19.86949" x2="19.86949" y1="29.19656" y2="18.53865"><stop offset="0.09694" style="stop-color:#FFD879"/><stop offset="0.15387" style="stop-color:#FCCB76"/><stop offset="0.25828" style="stop-color:#F5AA6C"/><stop offset="0.39756" style="stop-color:#E9755E"/><stop offset="0.44898" style="stop-color:#E45F58"/><stop offset="0.67857" style="stop-color:#D22A9C"/><stop offset="1" style="stop-color:#6968DF"/></linearGradient><path d="M19.86946,19.78577c-2.32996,0-4.20996,1.89001-4.20996,4.21002 c0,2.32996,1.88001,4.20996,4.20996,4.20996c2.32001,0,4.21002-1.88,4.21002-4.20996 C24.07948,21.67579,22.18946,19.78577,19.86946,19.78577z M19.86946,26.39576c-1.32996,0-2.40997-1.07001-2.40997-2.39996 c0-1.32001,1.08002-2.40002,2.40997-2.40002c1.32001,0,2.40002,1.08002,2.40002,2.40002 C22.26948,25.32575,21.18946,26.39576,19.86946,26.39576z" style="fill:url(#SVGID_2_);"/><circle cx="19.86524" cy="23.99844" r="4.21049" style="fill:none;stroke:#303030;stroke-width:0.7;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/><circle cx="19.86524" cy="23.99844" r="2.40228" style="fill:none;stroke:#303030;stroke-width:0.7;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/><line style="fill:none;stroke:#303030;stroke-width:0.7;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;" x1="15.30362" x2="21.07546" y1="17.41522" y2="17.41522"/><line style="fill:none;stroke:#303030;stroke-width:0.7;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;" x1="23.03044" x2="24.42686" y1="17.41522" y2="17.41522"/></g></g></svg>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><svg height="60px" version="1.1" viewBox="0 0 60 60" width="60px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title/><desc/><defs/><g fill="none" fill-rule="evenodd" id="Page-1" stroke="none" stroke-width="1"><g fill-rule="nonzero" id="008---Record"><g id="Icons" transform="translate(1.000000, 1.000000)"><path d="M58,29 C57.9846973,36.6755537 54.9206045,44.0305897 49.4819168,49.4467724 C44.0432292,54.8629552 36.6755511,57.896524 29,57.88 C28.33,57.88 27.66,57.86 27,57.8 C11.8148168,56.8192902 1.57651669e-14,44.216819 1.39888101e-14,29 C1.22124533e-14,13.783181 11.8148168,1.18070975 27,0.2 C27.66,0.14 28.33,0.12 29,0.12 C36.6755511,0.103475955 44.0432292,3.13704484 49.4819168,8.55322756 C54.9206045,13.9694103 57.9846973,21.3244463 58,29 Z" fill="#FC7308" id="Shape"/><ellipse cx="27" cy="29" fill="#FFA800" id="Oval" rx="27" ry="28.79999"/><path d="M55,29 C54.951764,43.3199666 43.3200365,54.8980092 29,54.88 C28.16,54.88 27.33,54.84 26.5,54.76 C13.1870891,53.5358138 3.00007599,42.3690773 3.00007599,29 C3.00007599,15.6309227 13.1870891,4.46418623 26.5,3.24 C27.33,3.16 28.16,3.12 29,3.12 C43.3200433,3.10197426 54.9517805,14.6800265 55,29 Z" fill="#FFA800" id="Shape"/><ellipse cx="26.5" cy="29" fill="#FEDD0A" id="Oval" rx="23.5" ry="25.76001"/><path d="M29,54.875 C14.7258624,54.8062083 3.20367241,43.1910968 3.24953355,28.9168671 C3.29539468,14.6426374 14.8919815,3.1018034 29.1662665,3.12473387 C43.4405514,3.14766433 54.9999997,14.7256966 55,29 C54.9492389,43.3181062 43.3181845,54.893242 29,54.875 Z M29,5.125 C15.8304243,5.19376862 5.20363798,15.9134441 5.24948467,29.0831195 C5.29533136,42.2527949 15.9964946,52.898223 29.1662298,52.8752983 C42.3359651,52.8523737 53.0000025,42.1697552 53,29 C52.950323,15.7860145 42.2140648,5.10567421 29,5.125 Z" fill="#FFA800" id="Shape"/><rect fill="#D22047" height="20" id="Rectangle-path" rx="2" width="20" x="19" y="19"/><rect fill="#DB4E6C" height="20" id="Rectangle-path" rx="2" width="16" x="19" y="19"/></g><g fill="#FFFFFF" id="Layer_13" transform="translate(2.000000, 1.000000)"><path d="M30.45,57.87 C19.7910404,58.3836418 9.71612985,52.98292 4.24340019,43.8217804 C-1.22932948,34.6606408 -1.20953185,23.2294893 4.29489728,14.0873611 C9.7993264,4.94523284 19.8928835,-0.420559164 30.55,0.13 C15.145871,0.847513201 3.01788694,13.53155 2.99117961,28.9523574 C2.96447229,44.3731649 15.0484487,57.0991344 30.45,57.87 Z" id="Shape"/></g><g id="Outline"><path d="M16.0625,5.85954 C6.29897817,11.5307177 0.867451531,22.4858264 2.2641,33.6902 C4.13261987,47.7767897 16.2972674,58.2037634 30.50391,57.89606 C37.3608842,57.7107382 43.9194384,55.0515519 48.9693,50.40921 C56.6726139,43.3491532 59.7637298,32.5642258 56.9697725,22.4954995 C54.1758152,12.4267731 45.9692316,4.77682917 35.72937,2.6958 C29.0070992,1.32575722 22.0159601,2.4503971 16.0625,5.85954 L15.0625,4.12754 C21.4401455,0.474040843 28.9302022,-0.731349087 36.13208,0.73677 C47.0891847,2.99279027 55.8621646,11.1912007 58.8540793,21.9706356 C61.845994,32.7500706 58.5535746,44.2973249 50.32672,51.878 C44.9178446,56.8519689 37.8913323,59.6999389 30.54572,59.89559 C19.3492616,60.167393 8.9464666,54.1363202 3.61909003,44.2847408 C-1.70828654,34.4331614 -1.05990617,22.4260142 5.29736,13.2054 C7.83729048,9.49129705 11.1732417,6.39011623 15.0625,4.12749 L16.0625,5.85954 Z" fill="#FFFFFF" id="Shape"/><path d="M36.13208,0.73676 C28.9302061,-0.731382101 21.4401447,0.473997925 15.0625,4.1275 L13.32526,5.24915 L12.45941,5.8139 L11.65076,6.45898 C11.4373854,6.62180782 11.2990886,6.86414131 11.2674323,7.13067364 C11.2357761,7.39720597 11.313462,7.66519188 11.48276,7.87347 C11.8281084,8.29304826 12.4426998,8.3660806 12.87676,8.03912 L13.6303,7.4353 L14.44042,6.9093 L16.0625,5.85956 C22.0159544,2.45040147 29.0070969,1.32575393 35.72937,2.6958 C45.9520337,4.80080655 54.1367306,12.4500995 56.9274694,22.5072205 C59.7182081,32.5643416 56.6455173,43.3374339 48.9693,50.40918 C43.9194463,55.0515382 37.3608895,57.7107362 30.50391,57.89606 C20.0565751,58.1522179 10.3488086,52.5255282 5.37803968,43.3329289 C0.407270798,34.1403297 1.01401525,22.9362131 6.94843,14.33417 L7.49298,13.53705 C7.7979463,13.0954139 7.71301483,12.4936685 7.29773,12.15369 C7.08707063,11.9833131 6.8151928,11.9079179 6.54687271,11.9454677 C6.27855262,11.9830174 6.03781618,12.1301499 5.88202,12.35181 L5.29736,13.20538 C-1.03700334,22.4302272 -1.67329452,34.4250335 3.64956026,44.2682637 C8.97241503,54.1114939 19.3582578,60.1459379 30.54572,59.89563 C37.8913398,59.6999697 44.9178544,56.851981 50.32672,51.87799 C58.5806943,44.3090149 61.8915517,32.749919 58.8964148,21.9588751 C55.9012779,11.1678311 47.1063945,2.96877631 36.13208,0.73676 Z" fill="#000000" id="Shape"/><path d="M8.5827,10.62109 C8.9882097,10.97915 9.5991306,10.9714442 9.99548,10.60327 C10.1759952,10.4198835 10.2789839,10.1740427 10.28308,9.91675 L10.26257,9.72717 C10.2503813,9.66084378 10.2296837,9.59636791 10.20099,9.53534 C10.1819242,9.47455471 10.1540838,9.4168795 10.11835,9.36414 C10.0806939,9.30866448 10.039319,9.25580654 9.99451,9.20593 C9.80893121,9.01624201 9.55650198,8.90669007 9.2912,8.9007 C8.73332269,8.91936219 8.2821242,9.36110311 8.25165,9.91846 C8.25921258,10.0521909 8.29387043,10.1829905 8.35352,10.30292 C8.40832935,10.4229679 8.48619839,10.5310733 8.5827,10.62109 Z" fill="#000000" id="Shape"/><path d="M30,55.875 C44.2741376,55.8062083 55.7963276,44.1910968 55.7504665,29.9168671 C55.7046053,15.6426374 44.1080185,4.1018034 29.8337335,4.12473387 C15.5594486,4.14766433 4.00000027,15.7256966 4,30 C4.05059081,44.3181773 15.6817451,55.8934126 30,55.875 Z M30,6.125 C43.1695757,6.19376862 53.796362,16.9134441 53.7505153,30.0831195 C53.7046686,43.2527949 43.0035054,53.898223 29.8337702,53.8752983 C16.6640349,53.8523737 5.99999752,43.1697552 6,30 C6.04967695,16.7860145 16.7859352,6.10567421 30,6.125 Z" fill="#000000" id="Shape"/><path d="M22,41 L38,41 C39.6561049,40.9981923 40.9981923,39.6561049 41,38 L41,22 C40.9981923,20.3438951 39.6561049,19.0018077 38,19 L22,19 C20.3438951,19.0018077 19.0018077,20.3438951 19,22 L19,38 C19.0018077,39.6561049 20.3438951,40.9981923 22,41 Z M21,22 C21.0005512,21.4479437 21.4479437,21.0005512 22,21 L38,21 C38.5520563,21.0005512 38.9994488,21.4479437 39,22 L39,38 C38.9994488,38.5520563 38.5520563,38.9994488 38,39 L22,39 C21.4479437,38.9994488 21.0005512,38.5520563 21,38 L21,22 Z" fill="#000000" id="Shape"/></g></g></g></svg>
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -0,0 +1,43 @@
1
+ TEMPLATE = '<tr class="animated slideInDown">
2
+ <td>
3
+ {{datetime}}
4
+ </td>
5
+ <td>{{message}}</td>
6
+ <td>
7
+ {{#user}}
8
+ {{full_name}}
9
+ {{#id}}
10
+ ({{.}})
11
+ {{/id}}
12
+ {{/user}}
13
+ </td>
14
+ <td>
15
+ {{category}}
16
+ </td>
17
+ <td>
18
+ <div class="tags">
19
+ {{#tags}}
20
+ <span class="tag is-small is-{{@val}}">{{@key}}</span>
21
+ {{/tags}}
22
+ </div>
23
+ </td>
24
+ </tr>';
25
+
26
+ App.updates = App.cable.subscriptions.create "RailsLive::UpdatesChannel",
27
+ connected: ->
28
+
29
+ disconnected: ->
30
+
31
+ received: (data) ->
32
+ $('.waiting-for-updates').hide()
33
+ $('#messages').removeClass('is-hidden')
34
+
35
+ options = {}
36
+ options['datetime'] = data['datetime']
37
+ options['tags'] = objs2list(data['tags'])
38
+ options['message'] = data['message']
39
+ options['category'] = data['category']
40
+ options['user'] = data['user']
41
+
42
+ html = Mustache.to_html(TEMPLATE, options)
43
+ $('#messages').prepend(html)
@@ -0,0 +1,26 @@
1
+ (function () {
2
+ this.App || (this.App = {});
3
+
4
+ App.cable = ActionCable.createConsumer();
5
+ }).call(this);
6
+
7
+ function objs2list(p) {
8
+ r = [];
9
+ for (var key in p)
10
+ if (p.hasOwnProperty(key)) {
11
+ r.push({
12
+ "@key": key,
13
+ "@val": p[key]
14
+ });
15
+ }
16
+ return r;
17
+ }
18
+
19
+ $(document).ready(function() {
20
+ // Check for click events on the navbar burger icon
21
+ $(".navbar-burger").click(function() {
22
+ // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
23
+ $(".navbar-burger").toggleClass("is-active");
24
+ $(".navbar-menu").toggleClass("is-active");
25
+ });
26
+ });
@@ -0,0 +1,7 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require rails_live/mustache.min.js
4
+ //= require activestorage
5
+ //= require action_cable
6
+ //= require rails_live/app.js
7
+ //= require channels/rails_live/updates.coffee
@@ -0,0 +1,682 @@
1
+ /*!
2
+ * mustache.js - Logic-less {{mustache}} templates with JavaScript
3
+ * http://github.com/janl/mustache.js
4
+ */
5
+
6
+ /*global define: false Mustache: true*/
7
+
8
+ (function defineMustache (global, factory) {
9
+ if (typeof exports === 'object' && exports && typeof exports.nodeName !== 'string') {
10
+ factory(exports); // CommonJS
11
+ } else if (typeof define === 'function' && define.amd) {
12
+ define(['exports'], factory); // AMD
13
+ } else {
14
+ global.Mustache = {};
15
+ factory(global.Mustache); // script, wsh, asp
16
+ }
17
+ }(this, function mustacheFactory (mustache) {
18
+
19
+ var objectToString = Object.prototype.toString;
20
+ var isArray = Array.isArray || function isArrayPolyfill (object) {
21
+ return objectToString.call(object) === '[object Array]';
22
+ };
23
+
24
+ function isFunction (object) {
25
+ return typeof object === 'function';
26
+ }
27
+
28
+ /**
29
+ * More correct typeof string handling array
30
+ * which normally returns typeof 'object'
31
+ */
32
+ function typeStr (obj) {
33
+ return isArray(obj) ? 'array' : typeof obj;
34
+ }
35
+
36
+ function escapeRegExp (string) {
37
+ return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
38
+ }
39
+
40
+ /**
41
+ * Null safe way of checking whether or not an object,
42
+ * including its prototype, has a given property
43
+ */
44
+ function hasProperty (obj, propName) {
45
+ return obj != null && typeof obj === 'object' && (propName in obj);
46
+ }
47
+
48
+ /**
49
+ * Safe way of detecting whether or not the given thing is a primitive and
50
+ * whether it has the given property
51
+ */
52
+ function primitiveHasOwnProperty (primitive, propName) {
53
+ return (
54
+ primitive != null
55
+ && typeof primitive !== 'object'
56
+ && primitive.hasOwnProperty
57
+ && primitive.hasOwnProperty(propName)
58
+ );
59
+ }
60
+
61
+ // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
62
+ // See https://github.com/janl/mustache.js/issues/189
63
+ var regExpTest = RegExp.prototype.test;
64
+ function testRegExp (re, string) {
65
+ return regExpTest.call(re, string);
66
+ }
67
+
68
+ var nonSpaceRe = /\S/;
69
+ function isWhitespace (string) {
70
+ return !testRegExp(nonSpaceRe, string);
71
+ }
72
+
73
+ var entityMap = {
74
+ '&': '&amp;',
75
+ '<': '&lt;',
76
+ '>': '&gt;',
77
+ '"': '&quot;',
78
+ "'": '&#39;',
79
+ '/': '&#x2F;',
80
+ '`': '&#x60;',
81
+ '=': '&#x3D;'
82
+ };
83
+
84
+ function escapeHtml (string) {
85
+ return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
86
+ return entityMap[s];
87
+ });
88
+ }
89
+
90
+ var whiteRe = /\s*/;
91
+ var spaceRe = /\s+/;
92
+ var equalsRe = /\s*=/;
93
+ var curlyRe = /\s*\}/;
94
+ var tagRe = /#|\^|\/|>|\{|&|=|!/;
95
+
96
+ /**
97
+ * Breaks up the given `template` string into a tree of tokens. If the `tags`
98
+ * argument is given here it must be an array with two string values: the
99
+ * opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
100
+ * course, the default is to use mustaches (i.e. mustache.tags).
101
+ *
102
+ * A token is an array with at least 4 elements. The first element is the
103
+ * mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
104
+ * did not contain a symbol (i.e. {{myValue}}) this element is "name". For
105
+ * all text that appears outside a symbol this element is "text".
106
+ *
107
+ * The second element of a token is its "value". For mustache tags this is
108
+ * whatever else was inside the tag besides the opening symbol. For text tokens
109
+ * this is the text itself.
110
+ *
111
+ * The third and fourth elements of the token are the start and end indices,
112
+ * respectively, of the token in the original template.
113
+ *
114
+ * Tokens that are the root node of a subtree contain two more elements: 1) an
115
+ * array of tokens in the subtree and 2) the index in the original template at
116
+ * which the closing tag for that section begins.
117
+ */
118
+ function parseTemplate (template, tags) {
119
+ if (!template)
120
+ return [];
121
+
122
+ var sections = []; // Stack to hold section tokens
123
+ var tokens = []; // Buffer to hold the tokens
124
+ var spaces = []; // Indices of whitespace tokens on the current line
125
+ var hasTag = false; // Is there a {{tag}} on the current line?
126
+ var nonSpace = false; // Is there a non-space char on the current line?
127
+
128
+ // Strips all whitespace tokens array for the current line
129
+ // if there was a {{#tag}} on it and otherwise only space.
130
+ function stripSpace () {
131
+ if (hasTag && !nonSpace) {
132
+ while (spaces.length)
133
+ delete tokens[spaces.pop()];
134
+ } else {
135
+ spaces = [];
136
+ }
137
+
138
+ hasTag = false;
139
+ nonSpace = false;
140
+ }
141
+
142
+ var openingTagRe, closingTagRe, closingCurlyRe;
143
+ function compileTags (tagsToCompile) {
144
+ if (typeof tagsToCompile === 'string')
145
+ tagsToCompile = tagsToCompile.split(spaceRe, 2);
146
+
147
+ if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)
148
+ throw new Error('Invalid tags: ' + tagsToCompile);
149
+
150
+ openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*');
151
+ closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1]));
152
+ closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1]));
153
+ }
154
+
155
+ compileTags(tags || mustache.tags);
156
+
157
+ var scanner = new Scanner(template);
158
+
159
+ var start, type, value, chr, token, openSection;
160
+ while (!scanner.eos()) {
161
+ start = scanner.pos;
162
+
163
+ // Match any text between tags.
164
+ value = scanner.scanUntil(openingTagRe);
165
+
166
+ if (value) {
167
+ for (var i = 0, valueLength = value.length; i < valueLength; ++i) {
168
+ chr = value.charAt(i);
169
+
170
+ if (isWhitespace(chr)) {
171
+ spaces.push(tokens.length);
172
+ } else {
173
+ nonSpace = true;
174
+ }
175
+
176
+ tokens.push([ 'text', chr, start, start + 1 ]);
177
+ start += 1;
178
+
179
+ // Check for whitespace on the current line.
180
+ if (chr === '\n')
181
+ stripSpace();
182
+ }
183
+ }
184
+
185
+ // Match the opening tag.
186
+ if (!scanner.scan(openingTagRe))
187
+ break;
188
+
189
+ hasTag = true;
190
+
191
+ // Get the tag type.
192
+ type = scanner.scan(tagRe) || 'name';
193
+ scanner.scan(whiteRe);
194
+
195
+ // Get the tag value.
196
+ if (type === '=') {
197
+ value = scanner.scanUntil(equalsRe);
198
+ scanner.scan(equalsRe);
199
+ scanner.scanUntil(closingTagRe);
200
+ } else if (type === '{') {
201
+ value = scanner.scanUntil(closingCurlyRe);
202
+ scanner.scan(curlyRe);
203
+ scanner.scanUntil(closingTagRe);
204
+ type = '&';
205
+ } else {
206
+ value = scanner.scanUntil(closingTagRe);
207
+ }
208
+
209
+ // Match the closing tag.
210
+ if (!scanner.scan(closingTagRe))
211
+ throw new Error('Unclosed tag at ' + scanner.pos);
212
+
213
+ token = [ type, value, start, scanner.pos ];
214
+ tokens.push(token);
215
+
216
+ if (type === '#' || type === '^') {
217
+ sections.push(token);
218
+ } else if (type === '/') {
219
+ // Check section nesting.
220
+ openSection = sections.pop();
221
+
222
+ if (!openSection)
223
+ throw new Error('Unopened section "' + value + '" at ' + start);
224
+
225
+ if (openSection[1] !== value)
226
+ throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
227
+ } else if (type === 'name' || type === '{' || type === '&') {
228
+ nonSpace = true;
229
+ } else if (type === '=') {
230
+ // Set the tags for the next time around.
231
+ compileTags(value);
232
+ }
233
+ }
234
+
235
+ // Make sure there are no open sections when we're done.
236
+ openSection = sections.pop();
237
+
238
+ if (openSection)
239
+ throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
240
+
241
+ return nestTokens(squashTokens(tokens));
242
+ }
243
+
244
+ /**
245
+ * Combines the values of consecutive text tokens in the given `tokens` array
246
+ * to a single token.
247
+ */
248
+ function squashTokens (tokens) {
249
+ var squashedTokens = [];
250
+
251
+ var token, lastToken;
252
+ for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
253
+ token = tokens[i];
254
+
255
+ if (token) {
256
+ if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
257
+ lastToken[1] += token[1];
258
+ lastToken[3] = token[3];
259
+ } else {
260
+ squashedTokens.push(token);
261
+ lastToken = token;
262
+ }
263
+ }
264
+ }
265
+
266
+ return squashedTokens;
267
+ }
268
+
269
+ /**
270
+ * Forms the given array of `tokens` into a nested tree structure where
271
+ * tokens that represent a section have two additional items: 1) an array of
272
+ * all tokens that appear in that section and 2) the index in the original
273
+ * template that represents the end of that section.
274
+ */
275
+ function nestTokens (tokens) {
276
+ var nestedTokens = [];
277
+ var collector = nestedTokens;
278
+ var sections = [];
279
+
280
+ var token, section;
281
+ for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
282
+ token = tokens[i];
283
+
284
+ switch (token[0]) {
285
+ case '#':
286
+ case '^':
287
+ collector.push(token);
288
+ sections.push(token);
289
+ collector = token[4] = [];
290
+ break;
291
+ case '/':
292
+ section = sections.pop();
293
+ section[5] = token[2];
294
+ collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens;
295
+ break;
296
+ default:
297
+ collector.push(token);
298
+ }
299
+ }
300
+
301
+ return nestedTokens;
302
+ }
303
+
304
+ /**
305
+ * A simple string scanner that is used by the template parser to find
306
+ * tokens in template strings.
307
+ */
308
+ function Scanner (string) {
309
+ this.string = string;
310
+ this.tail = string;
311
+ this.pos = 0;
312
+ }
313
+
314
+ /**
315
+ * Returns `true` if the tail is empty (end of string).
316
+ */
317
+ Scanner.prototype.eos = function eos () {
318
+ return this.tail === '';
319
+ };
320
+
321
+ /**
322
+ * Tries to match the given regular expression at the current position.
323
+ * Returns the matched text if it can match, the empty string otherwise.
324
+ */
325
+ Scanner.prototype.scan = function scan (re) {
326
+ var match = this.tail.match(re);
327
+
328
+ if (!match || match.index !== 0)
329
+ return '';
330
+
331
+ var string = match[0];
332
+
333
+ this.tail = this.tail.substring(string.length);
334
+ this.pos += string.length;
335
+
336
+ return string;
337
+ };
338
+
339
+ /**
340
+ * Skips all text until the given regular expression can be matched. Returns
341
+ * the skipped string, which is the entire tail if no match can be made.
342
+ */
343
+ Scanner.prototype.scanUntil = function scanUntil (re) {
344
+ var index = this.tail.search(re), match;
345
+
346
+ switch (index) {
347
+ case -1:
348
+ match = this.tail;
349
+ this.tail = '';
350
+ break;
351
+ case 0:
352
+ match = '';
353
+ break;
354
+ default:
355
+ match = this.tail.substring(0, index);
356
+ this.tail = this.tail.substring(index);
357
+ }
358
+
359
+ this.pos += match.length;
360
+
361
+ return match;
362
+ };
363
+
364
+ /**
365
+ * Represents a rendering context by wrapping a view object and
366
+ * maintaining a reference to the parent context.
367
+ */
368
+ function Context (view, parentContext) {
369
+ this.view = view;
370
+ this.cache = { '.': this.view };
371
+ this.parent = parentContext;
372
+ }
373
+
374
+ /**
375
+ * Creates a new context using the given view with this context
376
+ * as the parent.
377
+ */
378
+ Context.prototype.push = function push (view) {
379
+ return new Context(view, this);
380
+ };
381
+
382
+ /**
383
+ * Returns the value of the given name in this context, traversing
384
+ * up the context hierarchy if the value is absent in this context's view.
385
+ */
386
+ Context.prototype.lookup = function lookup (name) {
387
+ var cache = this.cache;
388
+
389
+ var value;
390
+ if (cache.hasOwnProperty(name)) {
391
+ value = cache[name];
392
+ } else {
393
+ var context = this, intermediateValue, names, index, lookupHit = false;
394
+
395
+ while (context) {
396
+ if (name.indexOf('.') > 0) {
397
+ intermediateValue = context.view;
398
+ names = name.split('.');
399
+ index = 0;
400
+
401
+ /**
402
+ * Using the dot notion path in `name`, we descend through the
403
+ * nested objects.
404
+ *
405
+ * To be certain that the lookup has been successful, we have to
406
+ * check if the last object in the path actually has the property
407
+ * we are looking for. We store the result in `lookupHit`.
408
+ *
409
+ * This is specially necessary for when the value has been set to
410
+ * `undefined` and we want to avoid looking up parent contexts.
411
+ *
412
+ * In the case where dot notation is used, we consider the lookup
413
+ * to be successful even if the last "object" in the path is
414
+ * not actually an object but a primitive (e.g., a string, or an
415
+ * integer), because it is sometimes useful to access a property
416
+ * of an autoboxed primitive, such as the length of a string.
417
+ **/
418
+ while (intermediateValue != null && index < names.length) {
419
+ if (index === names.length - 1)
420
+ lookupHit = (
421
+ hasProperty(intermediateValue, names[index])
422
+ || primitiveHasOwnProperty(intermediateValue, names[index])
423
+ );
424
+
425
+ intermediateValue = intermediateValue[names[index++]];
426
+ }
427
+ } else {
428
+ intermediateValue = context.view[name];
429
+
430
+ /**
431
+ * Only checking against `hasProperty`, which always returns `false` if
432
+ * `context.view` is not an object. Deliberately omitting the check
433
+ * against `primitiveHasOwnProperty` if dot notation is not used.
434
+ *
435
+ * Consider this example:
436
+ * ```
437
+ * Mustache.render("The length of a football field is {{#length}}{{length}}{{/length}}.", {length: "100 yards"})
438
+ * ```
439
+ *
440
+ * If we were to check also against `primitiveHasOwnProperty`, as we do
441
+ * in the dot notation case, then render call would return:
442
+ *
443
+ * "The length of a football field is 9."
444
+ *
445
+ * rather than the expected:
446
+ *
447
+ * "The length of a football field is 100 yards."
448
+ **/
449
+ lookupHit = hasProperty(context.view, name);
450
+ }
451
+
452
+ if (lookupHit) {
453
+ value = intermediateValue;
454
+ break;
455
+ }
456
+
457
+ context = context.parent;
458
+ }
459
+
460
+ cache[name] = value;
461
+ }
462
+
463
+ if (isFunction(value))
464
+ value = value.call(this.view);
465
+
466
+ return value;
467
+ };
468
+
469
+ /**
470
+ * A Writer knows how to take a stream of tokens and render them to a
471
+ * string, given a context. It also maintains a cache of templates to
472
+ * avoid the need to parse the same template twice.
473
+ */
474
+ function Writer () {
475
+ this.cache = {};
476
+ }
477
+
478
+ /**
479
+ * Clears all cached templates in this writer.
480
+ */
481
+ Writer.prototype.clearCache = function clearCache () {
482
+ this.cache = {};
483
+ };
484
+
485
+ /**
486
+ * Parses and caches the given `template` according to the given `tags` or
487
+ * `mustache.tags` if `tags` is omitted, and returns the array of tokens
488
+ * that is generated from the parse.
489
+ */
490
+ Writer.prototype.parse = function parse (template, tags) {
491
+ var cache = this.cache;
492
+ var cacheKey = template + ':' + (tags || mustache.tags).join(':');
493
+ var tokens = cache[cacheKey];
494
+
495
+ if (tokens == null)
496
+ tokens = cache[cacheKey] = parseTemplate(template, tags);
497
+
498
+ return tokens;
499
+ };
500
+
501
+ /**
502
+ * High-level method that is used to render the given `template` with
503
+ * the given `view`.
504
+ *
505
+ * The optional `partials` argument may be an object that contains the
506
+ * names and templates of partials that are used in the template. It may
507
+ * also be a function that is used to load partial templates on the fly
508
+ * that takes a single argument: the name of the partial.
509
+ *
510
+ * If the optional `tags` argument is given here it must be an array with two
511
+ * string values: the opening and closing tags used in the template (e.g.
512
+ * [ "<%", "%>" ]). The default is to mustache.tags.
513
+ */
514
+ Writer.prototype.render = function render (template, view, partials, tags) {
515
+ var tokens = this.parse(template, tags);
516
+ var context = (view instanceof Context) ? view : new Context(view);
517
+ return this.renderTokens(tokens, context, partials, template);
518
+ };
519
+
520
+ /**
521
+ * Low-level method that renders the given array of `tokens` using
522
+ * the given `context` and `partials`.
523
+ *
524
+ * Note: The `originalTemplate` is only ever used to extract the portion
525
+ * of the original template that was contained in a higher-order section.
526
+ * If the template doesn't use higher-order sections, this argument may
527
+ * be omitted.
528
+ */
529
+ Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) {
530
+ var buffer = '';
531
+
532
+ var token, symbol, value;
533
+ for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
534
+ value = undefined;
535
+ token = tokens[i];
536
+ symbol = token[0];
537
+
538
+ if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate);
539
+ else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate);
540
+ else if (symbol === '>') value = this.renderPartial(token, context, partials, originalTemplate);
541
+ else if (symbol === '&') value = this.unescapedValue(token, context);
542
+ else if (symbol === 'name') value = this.escapedValue(token, context);
543
+ else if (symbol === 'text') value = this.rawValue(token);
544
+
545
+ if (value !== undefined)
546
+ buffer += value;
547
+ }
548
+
549
+ return buffer;
550
+ };
551
+
552
+ Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate) {
553
+ var self = this;
554
+ var buffer = '';
555
+ var value = context.lookup(token[1]);
556
+
557
+ // This function is used to render an arbitrary template
558
+ // in the current context by higher-order sections.
559
+ function subRender (template) {
560
+ return self.render(template, context, partials);
561
+ }
562
+
563
+ if (!value) return;
564
+
565
+ if (isArray(value)) {
566
+ for (var j = 0, valueLength = value.length; j < valueLength; ++j) {
567
+ buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate);
568
+ }
569
+ } else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') {
570
+ buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate);
571
+ } else if (isFunction(value)) {
572
+ if (typeof originalTemplate !== 'string')
573
+ throw new Error('Cannot use higher-order sections without the original template');
574
+
575
+ // Extract the portion of the original template that the section contains.
576
+ value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender);
577
+
578
+ if (value != null)
579
+ buffer += value;
580
+ } else {
581
+ buffer += this.renderTokens(token[4], context, partials, originalTemplate);
582
+ }
583
+ return buffer;
584
+ };
585
+
586
+ Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate) {
587
+ var value = context.lookup(token[1]);
588
+
589
+ // Use JavaScript's definition of falsy. Include empty arrays.
590
+ // See https://github.com/janl/mustache.js/issues/186
591
+ if (!value || (isArray(value) && value.length === 0))
592
+ return this.renderTokens(token[4], context, partials, originalTemplate);
593
+ };
594
+
595
+ Writer.prototype.renderPartial = function renderPartial (token, context, partials) {
596
+ if (!partials) return;
597
+
598
+ var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
599
+ if (value != null)
600
+ return this.renderTokens(this.parse(value), context, partials, value);
601
+ };
602
+
603
+ Writer.prototype.unescapedValue = function unescapedValue (token, context) {
604
+ var value = context.lookup(token[1]);
605
+ if (value != null)
606
+ return value;
607
+ };
608
+
609
+ Writer.prototype.escapedValue = function escapedValue (token, context) {
610
+ var value = context.lookup(token[1]);
611
+ if (value != null)
612
+ return mustache.escape(value);
613
+ };
614
+
615
+ Writer.prototype.rawValue = function rawValue (token) {
616
+ return token[1];
617
+ };
618
+
619
+ mustache.name = 'mustache.js';
620
+ mustache.version = '2.3.2';
621
+ mustache.tags = [ '{{', '}}' ];
622
+
623
+ // All high-level mustache.* functions use this writer.
624
+ var defaultWriter = new Writer();
625
+
626
+ /**
627
+ * Clears all cached templates in the default writer.
628
+ */
629
+ mustache.clearCache = function clearCache () {
630
+ return defaultWriter.clearCache();
631
+ };
632
+
633
+ /**
634
+ * Parses and caches the given template in the default writer and returns the
635
+ * array of tokens it contains. Doing this ahead of time avoids the need to
636
+ * parse templates on the fly as they are rendered.
637
+ */
638
+ mustache.parse = function parse (template, tags) {
639
+ return defaultWriter.parse(template, tags);
640
+ };
641
+
642
+ /**
643
+ * Renders the `template` with the given `view` and `partials` using the
644
+ * default writer. If the optional `tags` argument is given here it must be an
645
+ * array with two string values: the opening and closing tags used in the
646
+ * template (e.g. [ "<%", "%>" ]). The default is to mustache.tags.
647
+ */
648
+ mustache.render = function render (template, view, partials, tags) {
649
+ if (typeof template !== 'string') {
650
+ throw new TypeError('Invalid template! Template should be a "string" ' +
651
+ 'but "' + typeStr(template) + '" was given as the first ' +
652
+ 'argument for mustache#render(template, view, partials)');
653
+ }
654
+
655
+ return defaultWriter.render(template, view, partials, tags);
656
+ };
657
+
658
+ // This is here for backwards compatibility with 0.4.x.,
659
+ /*eslint-disable */ // eslint wants camel cased function name
660
+ mustache.to_html = function to_html (template, view, partials, send) {
661
+ /*eslint-enable*/
662
+
663
+ var result = mustache.render(template, view, partials);
664
+
665
+ if (isFunction(send)) {
666
+ send(result);
667
+ } else {
668
+ return result;
669
+ }
670
+ };
671
+
672
+ // Export the escaping function so that the user may override it.
673
+ // See https://github.com/janl/mustache.js/issues/244
674
+ mustache.escape = escapeHtml;
675
+
676
+ // Export these mainly for testing, but also for advanced usage.
677
+ mustache.Scanner = Scanner;
678
+ mustache.Context = Context;
679
+ mustache.Writer = Writer;
680
+
681
+ return mustache;
682
+ }));