Class: GacoCms::ShortcodeParser
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- GacoCms::ShortcodeParser
- Defined in:
- app/services/gaco_cms/shortcode_parser.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#ignored_shortcodes ⇒ Object
readonly
Returns the value of attribute ignored_shortcodes.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(content, record, ignore: []) ⇒ ShortcodeParser
constructor
A new instance of ShortcodeParser.
Methods inherited from ApplicationService
Constructor Details
#initialize(content, record, ignore: []) ⇒ ShortcodeParser
Returns a new instance of ShortcodeParser.
7 8 9 10 11 12 |
# File 'app/services/gaco_cms/shortcode_parser.rb', line 7 def initialize(content, record, ignore: []) @content = content @record = record @ignored_shortcodes = Array(ignore) super end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'app/services/gaco_cms/shortcode_parser.rb', line 5 def content @content end |
#ignored_shortcodes ⇒ Object (readonly)
Returns the value of attribute ignored_shortcodes.
5 6 7 |
# File 'app/services/gaco_cms/shortcode_parser.rb', line 5 def ignored_shortcodes @ignored_shortcodes end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
5 6 7 |
# File 'app/services/gaco_cms/shortcode_parser.rb', line 5 def record @record end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/gaco_cms/shortcode_parser.rb', line 14 def call counter = 0 loop do detected = @content.scan(/#{shortcodes_regex}/).to_a break if detected.empty? break log("Too many levels detected, skipping after #{counter} levels", mode: :error) if counter > 5 detected.each { |item| @content = replace_shortcode(item) } counter += 1 end @content end |