From 8c8988800817f745529d4e74c0ca18c12b647ee8 Mon Sep 17 00:00:00 2001 From: Ray Zane Date: Thu, 6 Feb 2025 11:13:49 -0500 Subject: [PATCH] Don't depend on Sprockets (#48) This engine doesn't need to depend on Sprockets. Instead, we'll insert a middleware to expose our assets at `/assets/demo_mode`. These assets don't need to be compiled or minified. --- Gemfile.lock | 13 +++++++------ app/assets/stylesheets/demo_mode/application.css | 5 ----- app/views/layouts/demo_mode/application.html.erb | 6 ++++-- config.ru | 7 ++++++- demo_mode.gemspec | 4 ++-- gemfiles/rails_6_1.gemfile.lock | 13 +++++-------- gemfiles/rails_7_0.gemfile.lock | 9 +++------ gemfiles/rails_7_1.gemfile.lock | 9 +++------ gemfiles/rails_7_2.gemfile.lock | 9 +++------ gemfiles/rails_8_0.gemfile.lock | 9 +++------ lib/demo_mode.rb | 7 ++++++- lib/demo_mode/config.rb | 6 +++--- lib/demo_mode/engine.rb | 15 +++------------ lib/demo_mode/persona.rb | 2 +- lib/demo_mode/version.rb | 2 +- .../assets/demo_mode/demo_mode.css | 0 .../assets/demo_mode/demo_mode.js | 2 -- .../assets}/demo_mode/icon--tophat.png | Bin .../assets}/demo_mode/icon--user.png | Bin .../assets}/demo_mode/icon--users.png | Bin .../assets}/demo_mode/loader.png | Bin .../assets/demo_mode/vendor/normalize-v8.0.1.css | 0 public/assets/demo_mode/vendor/typed-v2.1.0.js | 2 ++ spec/demo_mode_spec.rb | 8 ++++---- 24 files changed, 56 insertions(+), 72 deletions(-) delete mode 100644 app/assets/stylesheets/demo_mode/application.css rename app/assets/stylesheets/demo_mode/default.css => public/assets/demo_mode/demo_mode.css (100%) rename app/assets/javascript/demo_mode/application.js => public/assets/demo_mode/demo_mode.js (99%) rename {app/assets/images => public/assets}/demo_mode/icon--tophat.png (100%) rename {app/assets/images => public/assets}/demo_mode/icon--user.png (100%) rename {app/assets/images => public/assets}/demo_mode/icon--users.png (100%) rename {app/assets/images => public/assets}/demo_mode/loader.png (100%) rename app/assets/stylesheets/demo_mode/normalize.css => public/assets/demo_mode/vendor/normalize-v8.0.1.css (100%) create mode 100644 public/assets/demo_mode/vendor/typed-v2.1.0.js diff --git a/Gemfile.lock b/Gemfile.lock index 2d6c2d0..bf52906 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,15 +1,13 @@ PATH remote: . specs: - demo_mode (1.5.0) + demo_mode (2.0.0) actionpack (>= 6.1, < 8.1) activejob (>= 6.1, < 8.1) activerecord (>= 6.1, < 8.1) activesupport (>= 6.1, < 8.1) cli-ui railties (>= 6.1, < 8.1) - sprockets-rails - typedjs-rails GEM remote: https://rubygems.org/ @@ -234,15 +232,16 @@ GEM sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.5.1) + sprockets-rails (3.5.2) actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) + sqlite3 (2.5.0-arm64-darwin) + sqlite3 (2.5.0-x86_64-darwin) + sqlite3 (2.5.0-x86_64-linux-gnu) stringio (3.1.0) thor (1.3.1) timeout (0.4.1) - typedjs-rails (2.0.9) - railties (>= 3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uncruft (0.3.4) @@ -274,6 +273,8 @@ DEPENDENCIES factory_bot net-smtp rspec-rails + sprockets-rails + sqlite3 uncruft webrick diff --git a/app/assets/stylesheets/demo_mode/application.css b/app/assets/stylesheets/demo_mode/application.css deleted file mode 100644 index b0d8d21..0000000 --- a/app/assets/stylesheets/demo_mode/application.css +++ /dev/null @@ -1,5 +0,0 @@ -/* - *= require_self - *= require ./normalize - *= require ./default - */ diff --git a/app/views/layouts/demo_mode/application.html.erb b/app/views/layouts/demo_mode/application.html.erb index e9c49ce..b96e78b 100644 --- a/app/views/layouts/demo_mode/application.html.erb +++ b/app/views/layouts/demo_mode/application.html.erb @@ -5,8 +5,10 @@ Demo Mode <%= favicon_link_tag '/favicon.ico' %> - <%= stylesheet_link_tag 'demo_mode/application', media: 'all' %> - <%= javascript_include_tag 'demo_mode/application' %> + + + + <%= csrf_meta_tags %> diff --git a/config.ru b/config.ru index bc703b8..74ffea5 100644 --- a/config.ru +++ b/config.ru @@ -25,7 +25,7 @@ end DemoMode.add_persona :the_sometimesperson do features << 'foobar' callout true - icon 'demo_mode/icon--tophat' + icon :tophat sign_in_as { DummyUser.create!(name: SecureRandom.uuid) } variant :the_rarely_person do @@ -77,6 +77,11 @@ end Combustion.path = 'spec/dummy' Combustion.initialize! :all do config.active_job.queue_adapter = :async + config.action_dispatch.show_exceptions = if ActiveSupport.version >= Gem::Version.new('7.1') + :none + else + false + end end run Combustion::Application diff --git a/demo_mode.gemspec b/demo_mode.gemspec index 8605642..2cdac17 100644 --- a/demo_mode.gemspec +++ b/demo_mode.gemspec @@ -28,8 +28,6 @@ Gem::Specification.new do |s| s.add_dependency 'activesupport', rails_constraints s.add_dependency 'cli-ui' s.add_dependency 'railties', rails_constraints - s.add_dependency 'sprockets-rails' - s.add_dependency 'typedjs-rails' s.add_development_dependency 'actionmailer', rails_constraints s.add_development_dependency 'appraisal' @@ -40,6 +38,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'factory_bot' s.add_development_dependency 'net-smtp' s.add_development_dependency 'rspec-rails' + s.add_development_dependency 'sprockets-rails' + s.add_development_dependency 'sqlite3' s.add_development_dependency 'uncruft' s.add_development_dependency 'webrick' end diff --git a/gemfiles/rails_6_1.gemfile.lock b/gemfiles/rails_6_1.gemfile.lock index d8f872f..59ecba2 100644 --- a/gemfiles/rails_6_1.gemfile.lock +++ b/gemfiles/rails_6_1.gemfile.lock @@ -1,15 +1,13 @@ PATH remote: .. specs: - demo_mode (1.5.0) + demo_mode (2.0.0) actionpack (>= 6.1, < 8.1) activejob (>= 6.1, < 8.1) activerecord (>= 6.1, < 8.1) activesupport (>= 6.1, < 8.1) cli-ui railties (>= 6.1, < 8.1) - sprockets-rails - typedjs-rails GEM remote: https://rubygems.org/ @@ -202,17 +200,15 @@ GEM sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) sqlite3 (1.7.0-arm64-darwin) sqlite3 (1.7.0-x86_64-darwin) sqlite3 (1.7.0-x86_64-linux) thor (1.3.0) timeout (0.4.1) - typedjs-rails (2.0.9) - railties (>= 3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uncruft (0.3.4) @@ -245,6 +241,7 @@ DEPENDENCIES net-smtp railties (~> 6.1.0) rspec-rails + sprockets-rails sqlite3 (~> 1.4) uncruft webrick diff --git a/gemfiles/rails_7_0.gemfile.lock b/gemfiles/rails_7_0.gemfile.lock index 27ed0ed..d2b71cd 100644 --- a/gemfiles/rails_7_0.gemfile.lock +++ b/gemfiles/rails_7_0.gemfile.lock @@ -1,15 +1,13 @@ PATH remote: .. specs: - demo_mode (1.5.0) + demo_mode (2.0.0) actionpack (>= 6.1, < 8.1) activejob (>= 6.1, < 8.1) activerecord (>= 6.1, < 8.1) activesupport (>= 6.1, < 8.1) cli-ui railties (>= 6.1, < 8.1) - sprockets-rails - typedjs-rails GEM remote: https://rubygems.org/ @@ -205,7 +203,7 @@ GEM sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.5.1) + sprockets-rails (3.5.2) actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) @@ -214,8 +212,6 @@ GEM sqlite3 (1.7.0-x86_64-linux) thor (1.3.0) timeout (0.4.1) - typedjs-rails (2.0.9) - railties (>= 3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uncruft (0.3.4) @@ -248,6 +244,7 @@ DEPENDENCIES net-smtp railties (~> 7.0.0) rspec-rails + sprockets-rails sqlite3 (~> 1.4) uncruft webrick diff --git a/gemfiles/rails_7_1.gemfile.lock b/gemfiles/rails_7_1.gemfile.lock index 355416b..3c7b970 100644 --- a/gemfiles/rails_7_1.gemfile.lock +++ b/gemfiles/rails_7_1.gemfile.lock @@ -1,15 +1,13 @@ PATH remote: .. specs: - demo_mode (1.5.0) + demo_mode (2.0.0) actionpack (>= 6.1, < 8.1) activejob (>= 6.1, < 8.1) activerecord (>= 6.1, < 8.1) activesupport (>= 6.1, < 8.1) cli-ui railties (>= 6.1, < 8.1) - sprockets-rails - typedjs-rails GEM remote: https://rubygems.org/ @@ -245,7 +243,7 @@ GEM sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.5.1) + sprockets-rails (3.5.2) actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) @@ -255,8 +253,6 @@ GEM stringio (3.1.2) thor (1.3.2) timeout (0.4.1) - typedjs-rails (2.0.9) - railties (>= 3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uncruft (0.3.4) @@ -289,6 +285,7 @@ DEPENDENCIES net-smtp railties (~> 7.1.0) rspec-rails + sprockets-rails sqlite3 (>= 1.4) uncruft webrick diff --git a/gemfiles/rails_7_2.gemfile.lock b/gemfiles/rails_7_2.gemfile.lock index 141dfb4..bcb891c 100644 --- a/gemfiles/rails_7_2.gemfile.lock +++ b/gemfiles/rails_7_2.gemfile.lock @@ -1,15 +1,13 @@ PATH remote: .. specs: - demo_mode (1.5.0) + demo_mode (2.0.0) actionpack (>= 6.1, < 8.1) activejob (>= 6.1, < 8.1) activerecord (>= 6.1, < 8.1) activesupport (>= 6.1, < 8.1) cli-ui railties (>= 6.1, < 8.1) - sprockets-rails - typedjs-rails GEM remote: https://rubygems.org/ @@ -241,7 +239,7 @@ GEM sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.5.1) + sprockets-rails (3.5.2) actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) @@ -251,8 +249,6 @@ GEM stringio (3.1.2) thor (1.3.2) timeout (0.4.1) - typedjs-rails (2.0.9) - railties (>= 3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uncruft (0.3.4) @@ -286,6 +282,7 @@ DEPENDENCIES net-smtp railties (~> 7.2.0) rspec-rails + sprockets-rails sqlite3 (>= 1.4) uncruft webrick diff --git a/gemfiles/rails_8_0.gemfile.lock b/gemfiles/rails_8_0.gemfile.lock index 557866b..ef7bb49 100644 --- a/gemfiles/rails_8_0.gemfile.lock +++ b/gemfiles/rails_8_0.gemfile.lock @@ -1,15 +1,13 @@ PATH remote: .. specs: - demo_mode (1.5.0) + demo_mode (2.0.0) actionpack (>= 6.1, < 8.1) activejob (>= 6.1, < 8.1) activerecord (>= 6.1, < 8.1) activesupport (>= 6.1, < 8.1) cli-ui railties (>= 6.1, < 8.1) - sprockets-rails - typedjs-rails GEM remote: https://rubygems.org/ @@ -241,7 +239,7 @@ GEM sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.5.1) + sprockets-rails (3.5.2) actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) @@ -251,8 +249,6 @@ GEM stringio (3.1.2) thor (1.3.2) timeout (0.4.1) - typedjs-rails (2.0.9) - railties (>= 3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uncruft (0.3.4) @@ -287,6 +283,7 @@ DEPENDENCIES net-smtp railties (~> 8.0.0) rspec-rails + sprockets-rails sqlite3 (>= 2.1) uncruft webrick diff --git a/lib/demo_mode.rb b/lib/demo_mode.rb index 8c1bf49..230d4ab 100644 --- a/lib/demo_mode.rb +++ b/lib/demo_mode.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'rails' -require 'typedjs-rails' require 'demo_mode/version' require 'demo_mode/clever_sequence' require 'demo_mode/config' @@ -9,6 +8,12 @@ require 'demo_mode/persona' module DemoMode + ICONS = { + tophat: "/assets/demo_mode/icon--tophat.png?v=#{VERSION}", + user: "/assets/demo_mode/icon--user.png?v=#{VERSION}", + users: "/assets/demo_mode/icon--users.png?v=#{VERSION}", + }.freeze + class << self delegate(*Config.configurations, to: :configuration) diff --git a/lib/demo_mode/config.rb b/lib/demo_mode/config.rb index 55c5400..96c8f03 100644 --- a/lib/demo_mode/config.rb +++ b/lib/demo_mode/config.rb @@ -39,7 +39,7 @@ def loader(&block) if block @loader = block else - @loader ||= ->(_) { image_tag('demo_mode/loader.png') } + @loader ||= ->(_) { image_tag("/assets/demo_mode/loader.png?v=#{VERSION}") } end end @@ -47,9 +47,9 @@ def icon(name_or_path = nil, &block) if block @icon = block elsif name_or_path - @path = name_or_path.is_a?(Symbol) ? "demo_mode/icon--#{name_or_path}" : name_or_path + @path = ICONS.fetch(name_or_path, name_or_path) else - @path ||= 'demo_mode/icon--user' + @path ||= ICONS.fetch(:user) path = @path @icon ||= ->(_) { image_tag path } end diff --git a/lib/demo_mode/engine.rb b/lib/demo_mode/engine.rb index da552f5..54fddce 100644 --- a/lib/demo_mode/engine.rb +++ b/lib/demo_mode/engine.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'sprockets/railtie' - module DemoMode class Engine < ::Rails::Engine isolate_namespace DemoMode @@ -12,23 +10,16 @@ class Engine < ::Rails::Engine load 'demo_mode/tasks.rb' end - initializer 'demo_mode' do |_app| + initializer 'demo_mode' do |app| require 'zeitwerk/version' raise 'DemoMode only supports Zeitwerk::VERSION >= 2.4.2' unless Gem::Version.new(Zeitwerk::VERSION) >= Gem::Version.new('2.4.2') Rails.autoloaders.main.on_load(DemoMode.app_base_controller_name) do DemoMode.app_base_controller_name.constantize.include Demoable end - end - end - initializer 'demo_mode.assets' do |app| - app.config.assets.precompile << 'demo_mode/application.css' - app.config.assets.precompile << 'demo_mode/application.js' - app.config.assets.precompile << 'demo_mode/icon--user.png' - app.config.assets.precompile << 'demo_mode/icon--users.png' - app.config.assets.precompile << 'demo_mode/icon--tophat.png' - app.config.assets.precompile << 'demo_mode/loader.png' + app.middleware.insert_before(ActionDispatch::Static, ActionDispatch::Static, "#{root}/public") + end end end end diff --git a/lib/demo_mode/persona.rb b/lib/demo_mode/persona.rb index 2223040..45733c5 100644 --- a/lib/demo_mode/persona.rb +++ b/lib/demo_mode/persona.rb @@ -15,7 +15,7 @@ def icon(name_or_path = nil, &block) if block @icon = block elsif name_or_path - @path = name_or_path.is_a?(Symbol) ? "demo_mode/icon--#{name_or_path}" : name_or_path + @path = ICONS.fetch(name_or_path, name_or_path) path = @path @icon = ->(_) { image_tag path } else diff --git a/lib/demo_mode/version.rb b/lib/demo_mode/version.rb index 3afd781..0520605 100644 --- a/lib/demo_mode/version.rb +++ b/lib/demo_mode/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DemoMode - VERSION = '1.5.0' + VERSION = '2.0.0' end diff --git a/app/assets/stylesheets/demo_mode/default.css b/public/assets/demo_mode/demo_mode.css similarity index 100% rename from app/assets/stylesheets/demo_mode/default.css rename to public/assets/demo_mode/demo_mode.css diff --git a/app/assets/javascript/demo_mode/application.js b/public/assets/demo_mode/demo_mode.js similarity index 99% rename from app/assets/javascript/demo_mode/application.js rename to public/assets/demo_mode/demo_mode.js index 2e92ada..1f9f8c4 100644 --- a/app/assets/javascript/demo_mode/application.js +++ b/public/assets/demo_mode/demo_mode.js @@ -1,5 +1,3 @@ -//= require typed - (function(document, performance, location) { function* getJSON(url) { while(true) { yield fetch(url).then(resp => resp.json()); } diff --git a/app/assets/images/demo_mode/icon--tophat.png b/public/assets/demo_mode/icon--tophat.png similarity index 100% rename from app/assets/images/demo_mode/icon--tophat.png rename to public/assets/demo_mode/icon--tophat.png diff --git a/app/assets/images/demo_mode/icon--user.png b/public/assets/demo_mode/icon--user.png similarity index 100% rename from app/assets/images/demo_mode/icon--user.png rename to public/assets/demo_mode/icon--user.png diff --git a/app/assets/images/demo_mode/icon--users.png b/public/assets/demo_mode/icon--users.png similarity index 100% rename from app/assets/images/demo_mode/icon--users.png rename to public/assets/demo_mode/icon--users.png diff --git a/app/assets/images/demo_mode/loader.png b/public/assets/demo_mode/loader.png similarity index 100% rename from app/assets/images/demo_mode/loader.png rename to public/assets/demo_mode/loader.png diff --git a/app/assets/stylesheets/demo_mode/normalize.css b/public/assets/demo_mode/vendor/normalize-v8.0.1.css similarity index 100% rename from app/assets/stylesheets/demo_mode/normalize.css rename to public/assets/demo_mode/vendor/normalize-v8.0.1.css diff --git a/public/assets/demo_mode/vendor/typed-v2.1.0.js b/public/assets/demo_mode/vendor/typed-v2.1.0.js new file mode 100644 index 0000000..cd270b2 --- /dev/null +++ b/public/assets/demo_mode/vendor/typed-v2.1.0.js @@ -0,0 +1,2 @@ +!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t||self).Typed=s()}(this,function(){function t(){return t=Object.assign?Object.assign.bind():function(t){for(var s=1;s0&&(e.strPos=e.currentElContent.length-1,e.strings.unshift(e.currentElContent)),e.sequence=[],e.strings)e.sequence[u]=u;e.arrayPos=0,e.stopNum=0,e.loop=e.options.loop,e.loopCount=e.options.loopCount,e.curLoop=0,e.shuffle=e.options.shuffle,e.pause={status:!1,typewrite:!0,curString:"",curStrPos:0},e.typingComplete=!1,e.autoInsertCss=e.options.autoInsertCss,e.autoInsertCss&&(this.appendCursorAnimationCss(e),this.appendFadeOutAnimationCss(e))},n.getCurrentElContent=function(t){return t.attr?t.el.getAttribute(t.attr):t.isInput?t.el.value:"html"===t.contentType?t.el.innerHTML:t.el.textContent},n.appendCursorAnimationCss=function(t){var s="data-typed-js-cursor-css";if(t.showCursor&&!document.querySelector("["+s+"]")){var e=document.createElement("style");e.setAttribute(s,"true"),e.innerHTML="\n .typed-cursor{\n opacity: 1;\n }\n .typed-cursor.typed-cursor--blink{\n animation: typedjsBlink 0.7s infinite;\n -webkit-animation: typedjsBlink 0.7s infinite;\n animation: typedjsBlink 0.7s infinite;\n }\n @keyframes typedjsBlink{\n 50% { opacity: 0.0; }\n }\n @-webkit-keyframes typedjsBlink{\n 0% { opacity: 1; }\n 50% { opacity: 0.0; }\n 100% { opacity: 1; }\n }\n ",document.body.appendChild(e)}},n.appendFadeOutAnimationCss=function(t){var s="data-typed-fadeout-js-css";if(t.fadeOut&&!document.querySelector("["+s+"]")){var e=document.createElement("style");e.setAttribute(s,"true"),e.innerHTML="\n .typed-fade-out{\n opacity: 0;\n transition: opacity .25s;\n }\n .typed-cursor.typed-cursor--blink.typed-fade-out{\n -webkit-animation: 0;\n animation: 0;\n }\n ",document.body.appendChild(e)}},e}()),n=new(/*#__PURE__*/function(){function t(){}var s=t.prototype;return s.typeHtmlChars=function(t,s,e){if("html"!==e.contentType)return s;var n=t.substring(s).charAt(0);if("<"===n||"&"===n){var i;for(i="<"===n?">":";";t.substring(s+1).charAt(0)!==i&&!(1+ ++s>t.length););s++}return s},s.backSpaceHtmlChars=function(t,s,e){if("html"!==e.contentType)return s;var n=t.substring(s).charAt(0);if(">"===n||";"===n){var i;for(i=">"===n?"<":"&";t.substring(s-1).charAt(0)!==i&&!(--s<0););s--}return s},t}());/*#__PURE__*/ +return function(){function t(t,s){e.load(this,s,t),this.begin()}var s=t.prototype;return s.toggle=function(){this.pause.status?this.start():this.stop()},s.stop=function(){this.typingComplete||this.pause.status||(this.toggleBlinking(!0),this.pause.status=!0,this.options.onStop(this.arrayPos,this))},s.start=function(){this.typingComplete||this.pause.status&&(this.pause.status=!1,this.pause.typewrite?this.typewrite(this.pause.curString,this.pause.curStrPos):this.backspace(this.pause.curString,this.pause.curStrPos),this.options.onStart(this.arrayPos,this))},s.destroy=function(){this.reset(!1),this.options.onDestroy(this)},s.reset=function(t){void 0===t&&(t=!0),clearInterval(this.timeout),this.replaceText(""),this.cursor&&this.cursor.parentNode&&(this.cursor.parentNode.removeChild(this.cursor),this.cursor=null),this.strPos=0,this.arrayPos=0,this.curLoop=0,t&&(this.insertCursor(),this.options.onReset(this),this.begin())},s.begin=function(){var t=this;this.options.onBegin(this),this.typingComplete=!1,this.shuffleStringsIfNeeded(this),this.insertCursor(),this.bindInputFocusEvents&&this.bindFocusEvents(),this.timeout=setTimeout(function(){0===t.strPos?t.typewrite(t.strings[t.sequence[t.arrayPos]],t.strPos):t.backspace(t.strings[t.sequence[t.arrayPos]],t.strPos)},this.startDelay)},s.typewrite=function(t,s){var e=this;this.fadeOut&&this.el.classList.contains(this.fadeOutClass)&&(this.el.classList.remove(this.fadeOutClass),this.cursor&&this.cursor.classList.remove(this.fadeOutClass));var i=this.humanizer(this.typeSpeed),r=1;!0!==this.pause.status?this.timeout=setTimeout(function(){s=n.typeHtmlChars(t,s,e);var i=0,o=t.substring(s);if("^"===o.charAt(0)&&/^\^\d+/.test(o)){var a=1;a+=(o=/\d+/.exec(o)[0]).length,i=parseInt(o),e.temporaryPause=!0,e.options.onTypingPaused(e.arrayPos,e),t=t.substring(0,s)+t.substring(s+a),e.toggleBlinking(!0)}if("`"===o.charAt(0)){for(;"`"!==t.substring(s+r).charAt(0)&&(r++,!(s+r>t.length)););var u=t.substring(0,s),p=t.substring(u.length+1,s+r),c=t.substring(s+r+1);t=u+p+c,r--}e.timeout=setTimeout(function(){e.toggleBlinking(!1),s>=t.length?e.doneTyping(t,s):e.keepTyping(t,s,r),e.temporaryPause&&(e.temporaryPause=!1,e.options.onTypingResumed(e.arrayPos,e))},i)},i):this.setPauseStatus(t,s,!0)},s.keepTyping=function(t,s,e){0===s&&(this.toggleBlinking(!1),this.options.preStringTyped(this.arrayPos,this));var n=t.substring(0,s+=e);this.replaceText(n),this.typewrite(t,s)},s.doneTyping=function(t,s){var e=this;this.options.onStringTyped(this.arrayPos,this),this.toggleBlinking(!0),this.arrayPos===this.strings.length-1&&(this.complete(),!1===this.loop||this.curLoop===this.loopCount)||(this.timeout=setTimeout(function(){e.backspace(t,s)},this.backDelay))},s.backspace=function(t,s){var e=this;if(!0!==this.pause.status){if(this.fadeOut)return this.initFadeOut();this.toggleBlinking(!1);var i=this.humanizer(this.backSpeed);this.timeout=setTimeout(function(){s=n.backSpaceHtmlChars(t,s,e);var i=t.substring(0,s);if(e.replaceText(i),e.smartBackspace){var r=e.strings[e.arrayPos+1];e.stopNum=r&&i===r.substring(0,s)?s:0}s>e.stopNum?(s--,e.backspace(t,s)):s<=e.stopNum&&(e.arrayPos++,e.arrayPos===e.strings.length?(e.arrayPos=0,e.options.onLastStringBackspaced(),e.shuffleStringsIfNeeded(),e.begin()):e.typewrite(e.strings[e.sequence[e.arrayPos]],s))},i)}else this.setPauseStatus(t,s,!1)},s.complete=function(){this.options.onComplete(this),this.loop?this.curLoop++:this.typingComplete=!0},s.setPauseStatus=function(t,s,e){this.pause.typewrite=e,this.pause.curString=t,this.pause.curStrPos=s},s.toggleBlinking=function(t){this.cursor&&(this.pause.status||this.cursorBlinking!==t&&(this.cursorBlinking=t,t?this.cursor.classList.add("typed-cursor--blink"):this.cursor.classList.remove("typed-cursor--blink")))},s.humanizer=function(t){return Math.round(Math.random()*t/2)+t},s.shuffleStringsIfNeeded=function(){this.shuffle&&(this.sequence=this.sequence.sort(function(){return Math.random()-.5}))},s.initFadeOut=function(){var t=this;return this.el.className+=" "+this.fadeOutClass,this.cursor&&(this.cursor.className+=" "+this.fadeOutClass),setTimeout(function(){t.arrayPos++,t.replaceText(""),t.strings.length>t.arrayPos?t.typewrite(t.strings[t.sequence[t.arrayPos]],0):(t.typewrite(t.strings[0],0),t.arrayPos=0)},this.fadeOutDelay)},s.replaceText=function(t){this.attr?this.el.setAttribute(this.attr,t):this.isInput?this.el.value=t:"html"===this.contentType?this.el.innerHTML=t:this.el.textContent=t},s.bindFocusEvents=function(){var t=this;this.isInput&&(this.el.addEventListener("focus",function(s){t.stop()}),this.el.addEventListener("blur",function(s){t.el.value&&0!==t.el.value.length||t.start()}))},s.insertCursor=function(){this.showCursor&&(this.cursor||(this.cursor=document.createElement("span"),this.cursor.className="typed-cursor",this.cursor.setAttribute("aria-hidden",!0),this.cursor.innerHTML=this.cursorChar,this.el.parentNode&&this.el.parentNode.insertBefore(this.cursor,this.el.nextSibling)))},t}()}); \ No newline at end of file diff --git a/spec/demo_mode_spec.rb b/spec/demo_mode_spec.rb index 7129c14..21b66bd 100644 --- a/spec/demo_mode_spec.rb +++ b/spec/demo_mode_spec.rb @@ -75,10 +75,10 @@ def self.enabled? end expect(render_value(described_class.logo)).to eq 'Combustion' # default - expect(render_value(described_class.loader)).to match %r{img src="/assets/demo_mode/loader-.+\.png"} + expect(render_value(described_class.loader)).to match %r{img src="/assets/demo_mode/loader\.png\?v=#{DemoMode::VERSION}"}o expect(described_class.personas.count).to eq 1 described_class.personas.first.tap do |persona| - expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--user-.+\.png"} # default + expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--user\.png\?v=#{DemoMode::VERSION}"}o # default expect(persona.features).to eq ['test'] expect(generated_persona).to be false expect(persona.generate!).to eq 'something_important' @@ -127,7 +127,7 @@ def self.enabled? expect(render_value(described_class.loader)).to match %r{img src="/images/loading-for-real.gif"} expect(described_class.personas.count).to eq 3 described_class.personas.first.tap do |persona| - expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--tophat-.+\.png"} + expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--tophat\.png\?v=#{DemoMode::VERSION}"}o expect(persona.features).to eq(['foo']) expect(generated_persona_1).to be false expect(persona.generate!(password: 'cool_password')).to eq 'banana' @@ -179,7 +179,7 @@ def self.enabled? described_class.personas.tap do |personas| expect(personas.count).to eq 1 personas.first.tap do |persona| - expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--users-.+\.png"} + expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--users\.png\?v=#{DemoMode::VERSION}"}o expect(persona.features).to eq ['foo'] expect(persona.generate!).to eq 'banana' end