From f80b85c21aeda4464b1dbf9cb5d803de0a9a00f6 Mon Sep 17 00:00:00 2001 From: Sampson Crowley Date: Mon, 29 Apr 2019 21:41:47 -0600 Subject: [PATCH] add multiline raw parsing and fix components config --- README.md | 15 ++++++ lib/inky.rb | 4 +- lib/inky/configuration.rb | 17 +++++- lib/inky/rails/version.rb | 2 +- spec/components_spec.rb | 39 ++++++++++++++ spec/configuration_spec.rb | 108 +++++++++++++++++++++++++++++-------- 6 files changed, 158 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 78f1d04..1a91500 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,21 @@ Here are the names of the defaults: } ``` +## Raw HTML + +If you need to include raw html, you can wrap raw content in `` tags + +```html + + + + +``` + +This is a feature intended for advanced users. You will be responsible for ensuring all markup between `` tags is valid. All content after an opening `` tag will be inserted "As Is" until the next closing `` tag. + +This means that `` tags CANNOT be nested + ## Programmatic Use The Inky parser can be accessed directly for programmatic use. diff --git a/lib/inky.rb b/lib/inky.rb index a97bfb6..41942fb 100644 --- a/lib/inky.rb +++ b/lib/inky.rb @@ -21,7 +21,7 @@ def initialize(options = {}) spacer: 'spacer', wrapper: 'wrapper', menu_item: 'item' - }.merge(options[:components] || {}) + }.merge(::Inky.configuration.components).merge(options[:components] || {}) self.component_lookup = components.invert @@ -58,7 +58,7 @@ def transform_doc(elem) def self.extract_raws(string) raws = [] i = 0 - regex = %r(< *raw *>(.*?)) + regex = %r(<\s*raw\s*>((?!).*?))misux str = string while raw = str.match(regex) raws[i] = raw[1] diff --git a/lib/inky/configuration.rb b/lib/inky/configuration.rb index 90026e3..5c7711b 100644 --- a/lib/inky/configuration.rb +++ b/lib/inky/configuration.rb @@ -7,7 +7,7 @@ def self.configuration # Set Inky's configuration # @param config [Inky::Configuration] def self.configuration=(config) - @configuration = config + @configuration = config if config.is_a?(Configuration) end # Modify Inky's current configuration @@ -23,11 +23,24 @@ def self.configure end class Configuration - attr_accessor :template_engine, :column_count + attr_reader :template_engine, :column_count, :components def initialize @template_engine = :erb @column_count = 12 + @components = {} + end + + def template_engine=(value) + @template_engine = value.to_sym + end + + def components=(value) + @components = value if value.is_a?(Hash) + end + + def column_count=(value) + @column_count = value if value.is_a?(Integer) end end end diff --git a/lib/inky/rails/version.rb b/lib/inky/rails/version.rb index 92fdfe5..18382a5 100644 --- a/lib/inky/rails/version.rb +++ b/lib/inky/rails/version.rb @@ -1,6 +1,6 @@ module Inky module Rails - VERSION = '1.3.7.5'.freeze + VERSION = '1.3.7.6'.freeze end NODE_VERSION, GEM_VERSION = Rails::VERSION.rpartition('.').map(&:freeze) end diff --git a/spec/components_spec.rb b/spec/components_spec.rb index 848ed2c..2878901 100644 --- a/spec/components_spec.rb +++ b/spec/components_spec.rb @@ -361,4 +361,43 @@ output = inky.release_the_kraken(input) expect(output).to eql(expected) end + + it 'works on multiple lines' do + input = <<-HTML + + + <>\ +