From 5c72a19ed3e4be97e7e9823771e20f4266d23015 Mon Sep 17 00:00:00 2001 From: Raffi Date: Tue, 19 Feb 2019 09:18:47 +0000 Subject: [PATCH 1/3] Speed up block detection by eliminating NameError were possible --- lib/sir_trevor_rails/block.rb | 18 ++++++++++++++---- sir_trevor_rails.gemspec | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/sir_trevor_rails/block.rb b/lib/sir_trevor_rails/block.rb index c470a1d..0f38908 100644 --- a/lib/sir_trevor_rails/block.rb +++ b/lib/sir_trevor_rails/block.rb @@ -13,6 +13,11 @@ def format send(:[], :format).present? ? send(:[], :format).to_sym : DEFAULT_FORMAT end + # Sets a list of custom block types to speed up lookup at runtime. + def self.custom_block_types + [] + end + def initialize(hash, parent) @raw_data = hash @parent = parent @@ -40,10 +45,15 @@ def as_json(*attrs) # # @param [Symbol] type def self.block_class(type) - block_name = "#{type.to_s.camelize}Block" - begin - block_name.constantize - rescue NameError + type_name = type.to_s.camelize + block_name = "#{type_name}Block" + if custom_block_types.include?(type_name) + begin + block_name.constantize + rescue NameError + block_class!(block_name) + end + else block_class!(block_name) end end diff --git a/sir_trevor_rails.gemspec b/sir_trevor_rails.gemspec index eb634cb..24298d3 100644 --- a/sir_trevor_rails.gemspec +++ b/sir_trevor_rails.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "wrong" spec.add_development_dependency "pry-rails" spec.add_development_dependency "combustion" - spec.add_development_dependency "sqlite3" + spec.add_development_dependency "sqlite3", "~> 1.3.6" spec.add_development_dependency "capybara" spec.add_development_dependency "launchy" From 452bc28f999b3118f369e7f2f7a62a741459a0ec Mon Sep 17 00:00:00 2001 From: Raffi Date: Tue, 19 Feb 2019 09:26:33 +0000 Subject: [PATCH 2/3] Add readme for 0.6 --- CHANGELOG | 4 ++++ README.md | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 2a43d07..f3718ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v0.6.0: + date: 2019-02-19 + - Added custom_block_types to improve block class lookup performance + v0.4.0: date: 2014-05-20 changes: diff --git a/README.md b/README.md index 58f96d6..addd4df 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,23 @@ # Sir Trevor Rails -A Rails gem for integrating Sir Trevor JS into your Rails 3/4 application. +A Rails gem for integrating Sir Trevor JS into your Rails 3/4/5 application. + +## Upgrade guide to v0.6.0 + +There is a breaking change which needs to be applied if you've defined custom ruby blocks. + +Create an initializer ``config/initializers/sir_trevor_rails.rb`` + +Add your custom block types in the initializer: + +```ruby +class SirTrevorRails::Block + def self.custom_block_types + # Type should be string based and prefix of your class name. + ["Custom"] # Would relate to CustomBlock + end +end +``` ## Upgrade guide from v0.4.0-rc.1 @@ -74,6 +91,22 @@ Does this content have an image block? Return the first video block in the content +## Add custom block types with custom methods + +Create an initializer ``config/initializers/sir_trevor_rails.rb`` + +Add your custom block types in the initializer: + +```ruby +class SirTrevorRails::Block + def self.custom_block_types + # Type should be string based and prefix of your class name which would be for the following. + # TextBlock, HeadingBlock, CustomBlock + ["Text", "Heading", "Custom"] + end +end +``` + ## Add custom methods for block content Create an initializer ``config/initializers/sir_trevor_rails.rb`` From d5edf5fec9a212a6b56b662e4b400d05fd1f4e18 Mon Sep 17 00:00:00 2001 From: Raffi Date: Tue, 19 Feb 2019 09:29:20 +0000 Subject: [PATCH 3/3] Tabs for spaces in changelog --- CHANGELOG | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f3718ce..09b384e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ v0.6.0: - date: 2019-02-19 - - Added custom_block_types to improve block class lookup performance + date: 2019-02-19 + - Added custom_block_types to improve block class lookup performance v0.4.0: date: 2014-05-20