sir_trevor_rails 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a17365d69117d59bd658fb0da6a53f491c2cfde4
4
- data.tar.gz: 10245b86003a4e821bd35e55d99d3083c7ccf062
2
+ SHA256:
3
+ metadata.gz: 0a1c2cf1f3e25b93298e404ad2cf3ff350c6ca6668414e80eda23a6addb2848f
4
+ data.tar.gz: 16be7ad703a0dc2a80591db4d56674b0ce42a6b776d0aaa129a113ed244e20be
5
5
  SHA512:
6
- metadata.gz: fad85e8fe836fa24329d8cb838852c6e225449b84618cc552c705d70a9777c8eded15e9d8004ce6c6b1db6d8caaa24a9b2cab315b213a8cfb44cf974d1df5353
7
- data.tar.gz: b327975f26172138c53a74fcb07077085858f3e353719f8cd52679039404296cf7875483da612297d6aa67a98da77ce57cec87a103f847c5cf639877bed4b01c
6
+ metadata.gz: 3e1463ab7d9fd6391847c59f0c55750c77bea92aff5f1f6243826bf3dd61bb8602ccafea476498693a51eb35f42ea96bdf5173bf4f34620130d317bf8464e70c
7
+ data.tar.gz: b6a1c1bf4ab98089114180645f0221e12a8cba880a08375e4736b39ca06e9f346ec4c746a8a973d69631535f5310162a66781add2f9940b8d2e1090e77122fdf
@@ -5,5 +5,6 @@ rvm:
5
5
  - 2.1.0
6
6
  - 2.2.5
7
7
  - 2.3.1
8
+ - 2.6.5
8
9
 
9
10
  script: 'bundle exec rake test'
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ v0.6.1:
2
+ date: 2020-02-12
3
+ - Rails 6 support
4
+ v0.6.0:
5
+ date: 2019-02-19
6
+ - Added custom_block_types to improve block class lookup performance
7
+
1
8
  v0.4.0:
2
9
  date: 2014-05-20
3
10
  changes:
data/Gemfile CHANGED
@@ -6,4 +6,5 @@ gemspec
6
6
  if RUBY_VERSION < '2.2'
7
7
  gem 'rack', '< 2'
8
8
  gem 'rails', '< 5'
9
+ gem 'sqlite3', '~> 1.3.0'
9
10
  end
data/README.md CHANGED
@@ -1,6 +1,23 @@
1
1
  # Sir Trevor Rails
2
2
 
3
- A Rails gem for integrating Sir Trevor JS into your Rails 3/4 application.
3
+ A Rails gem for integrating Sir Trevor JS into your Rails 3/4/5/6 application.
4
+
5
+ ## Upgrade guide to v0.6.0
6
+
7
+ There is a breaking change which needs to be applied if you've defined custom ruby blocks.
8
+
9
+ Create an initializer ``config/initializers/sir_trevor_rails.rb``
10
+
11
+ Add your custom block types in the initializer:
12
+
13
+ ```ruby
14
+ class SirTrevorRails::Block
15
+ def self.custom_block_types
16
+ # Type should be string based and prefix of your class name.
17
+ ["Custom"] # Would relate to CustomBlock
18
+ end
19
+ end
20
+ ```
4
21
 
5
22
  ## Upgrade guide from v0.4.0-rc.1
6
23
 
@@ -74,6 +91,22 @@ Does this content have an image block?
74
91
 
75
92
  Return the first video block in the content
76
93
 
94
+ ## Add custom block types with custom methods
95
+
96
+ Create an initializer ``config/initializers/sir_trevor_rails.rb``
97
+
98
+ Add your custom block types in the initializer:
99
+
100
+ ```ruby
101
+ class SirTrevorRails::Block
102
+ def self.custom_block_types
103
+ # Type should be string based and prefix of your class name which would be for the following.
104
+ # TextBlock, HeadingBlock, CustomBlock
105
+ ["Text", "Heading", "Custom"]
106
+ end
107
+ end
108
+ ```
109
+
77
110
  ## Add custom methods for block content
78
111
 
79
112
  Create an initializer ``config/initializers/sir_trevor_rails.rb``
@@ -110,8 +143,7 @@ Ruby block classes can be used like decorators for the block content. See the [t
110
143
 
111
144
  ## Requirements
112
145
 
113
-
114
- - Rails 3.x/4.x
146
+ - Rails 3.x/4.x/5.x/6.x
115
147
 
116
148
  ## To do
117
149
 
@@ -13,6 +13,11 @@ module SirTrevorRails
13
13
  send(:[], :format).present? ? send(:[], :format).to_sym : DEFAULT_FORMAT
14
14
  end
15
15
 
16
+ # Sets a list of custom block types to speed up lookup at runtime.
17
+ def self.custom_block_types
18
+ []
19
+ end
20
+
16
21
  def initialize(hash, parent)
17
22
  @raw_data = hash
18
23
  @parent = parent
@@ -40,10 +45,15 @@ module SirTrevorRails
40
45
  #
41
46
  # @param [Symbol] type
42
47
  def self.block_class(type)
43
- block_name = "#{type.to_s.camelize}Block"
44
- begin
45
- block_name.constantize
46
- rescue NameError
48
+ type_name = type.to_s.camelize
49
+ block_name = "#{type_name}Block"
50
+ if custom_block_types.include?(type_name)
51
+ begin
52
+ block_name.constantize
53
+ rescue NameError
54
+ block_class!(block_name)
55
+ end
56
+ else
47
57
  block_class!(block_name)
48
58
  end
49
59
  end
@@ -29,5 +29,10 @@ module SirTrevorRails
29
29
  klass = Block.block_class(type)
30
30
  detect { |b| b.is_a? klass }
31
31
  end
32
+
33
+ def get_blocks_of_types(types)
34
+ types = [types] unless types.is_a? Array
35
+ select { |b| types.include?(b.type) }
36
+ end
32
37
  end
33
38
  end
@@ -1,3 +1,3 @@
1
1
  module SirTrevorRails
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -24,17 +24,17 @@ Gem::Specification.new do |spec|
24
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.4"
27
+ spec.add_development_dependency "bundler", ">= 1.4"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "minitest", "~> 5.3"
30
30
  spec.add_development_dependency "wrong"
31
31
  spec.add_development_dependency "pry-rails"
32
- spec.add_development_dependency "combustion"
33
- spec.add_development_dependency "sqlite3"
32
+ spec.add_development_dependency "combustion", "~> 1.1"
33
+ spec.add_development_dependency "sqlite3", ">= 1.3", "< 1.5"
34
34
  spec.add_development_dependency "capybara"
35
35
  spec.add_development_dependency "launchy"
36
36
 
37
- spec.add_dependency "rails", ">= 3", "< 6"
37
+ spec.add_dependency "rails", ">= 3", "< 7"
38
38
  spec.add_dependency "redcarpet", ">= 2.0.1", "< 4"
39
39
  spec.add_dependency "twitter-text", "~> 1.4"
40
40
  spec.add_dependency 'multi_json', '~> 1.0'
@@ -1,4 +1,8 @@
1
1
  require 'sir_trevor_rails'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
2
6
  require 'combustion'
3
7
 
4
8
  Combustion.initialize! :active_record, :action_view do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  class BlockArraySpec < ActiveSupport::TestCase
4
4
  describe BlockArray do
5
- describe 'intialization' do
5
+ describe 'initialization' do
6
6
  subject { BlockArray }
7
7
 
8
8
  it 'can be initialized with an empty JSON array' do
@@ -65,6 +65,25 @@ class BlockArraySpec < ActiveSupport::TestCase
65
65
  end
66
66
  end
67
67
 
68
+ describe 'get_blocks_of_types' do
69
+ it 'returns all blocks of given types in the array' do
70
+ text_blocks = subject.get_blocks_of_types(:text)
71
+ text_blocks.each do |b|
72
+ assert { b.type == :text }
73
+ end
74
+ end
75
+
76
+ it 'returns correct number of blocks of given types in the array' do
77
+ text_blocks = subject.get_blocks_of_types([:text, :list])
78
+ assert { text_blocks.size == 2 }
79
+ end
80
+
81
+ it 'returns empty array if called with block type not in the array' do
82
+ nonexistent_blocks = subject.get_blocks_of_types(:nonexistent)
83
+ assert { nonexistent_blocks.size == 0 }
84
+ end
85
+ end
86
+
68
87
  describe 'to_a' do
69
88
  it 'returns array with same number of elements' do
70
89
  assert { subject.to_a.class == Array }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sir_trevor_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Sprinz
@@ -11,20 +11,20 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-07-08 00:00:00.000000000 Z
14
+ date: 2020-02-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - "~>"
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: '1.4'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.4'
30
30
  - !ruby/object:Gem::Dependency
@@ -87,30 +87,36 @@ dependencies:
87
87
  name: combustion
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - ">="
90
+ - - "~>"
91
91
  - !ruby/object:Gem::Version
92
- version: '0'
92
+ version: '1.1'
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
97
+ - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: '0'
99
+ version: '1.1'
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: sqlite3
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: '0'
106
+ version: '1.3'
107
+ - - "<"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.5'
107
110
  type: :development
108
111
  prerelease: false
109
112
  version_requirements: !ruby/object:Gem::Requirement
110
113
  requirements:
111
114
  - - ">="
112
115
  - !ruby/object:Gem::Version
113
- version: '0'
116
+ version: '1.3'
117
+ - - "<"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.5'
114
120
  - !ruby/object:Gem::Dependency
115
121
  name: capybara
116
122
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +154,7 @@ dependencies:
148
154
  version: '3'
149
155
  - - "<"
150
156
  - !ruby/object:Gem::Version
151
- version: '6'
157
+ version: '7'
152
158
  type: :runtime
153
159
  prerelease: false
154
160
  version_requirements: !ruby/object:Gem::Requirement
@@ -158,7 +164,7 @@ dependencies:
158
164
  version: '3'
159
165
  - - "<"
160
166
  - !ruby/object:Gem::Version
161
- version: '6'
167
+ version: '7'
162
168
  - !ruby/object:Gem::Dependency
163
169
  name: redcarpet
164
170
  requirement: !ruby/object:Gem::Requirement
@@ -301,8 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
307
  - !ruby/object:Gem::Version
302
308
  version: '0'
303
309
  requirements: []
304
- rubyforge_project:
305
- rubygems_version: 2.2.2
310
+ rubygems_version: 3.0.3
306
311
  signing_key:
307
312
  specification_version: 4
308
313
  summary: A ruby wrapper for sir trevor content
@@ -338,4 +343,3 @@ test_files:
338
343
  - spec/unit/custom_block_spec.rb
339
344
  - spec/unit/has_sir_trevor_content_spec.rb
340
345
  - spec/unit/helpers_spec.rb
341
- has_rdoc: