inky-rb 1.3.7.0 → 1.3.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +119 -8
- data/README.md +27 -2
- data/inky.gemspec +6 -2
- data/lib/generators/inky/install_generator.rb +3 -2
- data/lib/generators/inky/templates/mailer_layout.html.erb +2 -2
- data/lib/generators/inky/templates/mailer_layout.html.haml +13 -0
- data/lib/generators/inky/templates/mailer_layout.html.slim +15 -0
- data/lib/inky.rb +9 -8
- data/lib/inky/component_factory.rb +139 -0
- data/lib/inky/configuration.rb +31 -0
- data/lib/inky/rails/engine.rb +1 -1
- data/lib/inky/rails/template_handler.rb +24 -8
- data/lib/inky/rails/version.rb +1 -1
- data/spec/configuration_spec.rb +38 -0
- data/spec/inky_spec.rb +19 -0
- data/spec/spec_helper.rb +5 -5
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/inky_controller.rb +9 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/mailers/application_mailer.rb +4 -0
- data/spec/test_app/app/views/inky/_inky_partial.html.inky +1 -0
- data/spec/test_app/app/views/inky/explicit_builder.html.inky-builder +1 -0
- data/spec/test_app/app/views/inky/explicit_slim.html.inky-slim +2 -0
- data/spec/test_app/app/views/inky/layout.html.erb +1 -0
- data/spec/test_app/app/views/inky/non_inky.html.erb +3 -0
- data/spec/test_app/app/views/inky/simple.html.inky +1 -0
- data/spec/test_app/app/views/inky/slim.html.inky +2 -0
- data/spec/test_app/app/views/layouts/application.html.erb +4 -0
- data/spec/test_app/app/views/layouts/inky_layout.html.inky +11 -0
- data/spec/test_app/config.ru +5 -0
- data/spec/test_app/config/application.rb +22 -0
- data/spec/test_app/config/boot.rb +5 -0
- data/spec/test_app/config/cable.yml +9 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +54 -0
- data/spec/test_app/config/environments/production.rb +86 -0
- data/spec/test_app/config/environments/test.rb +44 -0
- data/spec/test_app/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/test_app/config/initializers/assets.rb +11 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/test_app/config/initializers/secret_token.rb +1 -0
- data/spec/test_app/config/initializers/session_store.rb +3 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +23 -0
- data/spec/test_app/config/puma.rb +47 -0
- data/spec/test_app/config/routes.rb +3 -0
- data/spec/test_app/config/secrets.yml +22 -0
- data/spec/test_app/config/spring.rb +6 -0
- data/spec/test_app/log/.keep +0 -0
- data/spec/test_app/spec/features/inky_spec.rb +100 -0
- data/spec/test_app/spec/helper.rb +14 -0
- metadata +197 -5
- data/lib/component_factory.rb +0 -138
@@ -0,0 +1,31 @@
|
|
1
|
+
module Inky
|
2
|
+
# @return [Inky::Configuration] Inky's current configuration
|
3
|
+
def self.configuration
|
4
|
+
@configuration ||= Configuration.new
|
5
|
+
end
|
6
|
+
|
7
|
+
# Set Inky's configuration
|
8
|
+
# @param config [Inky::Configuration]
|
9
|
+
def self.configuration=(config)
|
10
|
+
@configuration = config
|
11
|
+
end
|
12
|
+
|
13
|
+
# Modify Inky's current configuration
|
14
|
+
# @yieldparam [Inky::Configuration] config current Inky config
|
15
|
+
# ```
|
16
|
+
# Inky.configure do |config|
|
17
|
+
# config.template_engine = :slim
|
18
|
+
# end
|
19
|
+
# ```
|
20
|
+
def self.configure
|
21
|
+
yield configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
class Configuration
|
25
|
+
attr_accessor :template_engine
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@template_engine = :erb
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/inky/rails/engine.rb
CHANGED
@@ -4,7 +4,7 @@ module Inky
|
|
4
4
|
module Rails
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
if config.respond_to?(:annotations)
|
7
|
-
config.annotations.register_extensions("inky") { |annotation|
|
7
|
+
config.annotations.register_extensions("inky") { |annotation| /<!--\s*(#{annotation}):?\s*(.*) -->/ }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -1,14 +1,26 @@
|
|
1
1
|
module Inky
|
2
2
|
module Rails
|
3
3
|
class TemplateHandler
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def initialize(compose_with = nil)
|
5
|
+
@engine_handler = ActionView::Template.registered_template_handler(compose_with) if compose_with
|
6
|
+
end
|
7
|
+
|
8
|
+
def engine_handler
|
9
|
+
return @engine_handler if @engine_handler
|
10
|
+
type = ::Inky.configuration.template_engine
|
11
|
+
ActionView::Template.registered_template_handler(type) ||
|
12
|
+
raise("No template handler found for #{type}")
|
13
|
+
end
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
def call(template)
|
16
|
+
compiled_source = engine_handler.call(template)
|
17
|
+
"Inky::Core.new.release_the_kraken(begin; #{compiled_source};end)"
|
18
|
+
end
|
19
|
+
|
20
|
+
module Composer
|
21
|
+
def register_template_handler(ext, *)
|
22
|
+
super
|
23
|
+
super :"inky-#{ext}", Inky::Rails::TemplateHandler.new(ext)
|
12
24
|
end
|
13
25
|
end
|
14
26
|
end
|
@@ -16,5 +28,9 @@ module Inky
|
|
16
28
|
end
|
17
29
|
|
18
30
|
ActiveSupport.on_load(:action_view) do
|
19
|
-
ActionView::Template.
|
31
|
+
ActionView::Template.template_handler_extensions.each do |ext|
|
32
|
+
ActionView::Template.register_template_handler :"inky-#{ext}", Inky::Rails::TemplateHandler.new(ext)
|
33
|
+
end
|
34
|
+
ActionView::Template.register_template_handler :inky, Inky::Rails::TemplateHandler.new
|
35
|
+
ActionView::Template.singleton_class.send :prepend, Inky::Rails::TemplateHandler::Composer
|
20
36
|
end
|
data/lib/inky/rails/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe "Configuration" do
|
4
|
+
around do |spec|
|
5
|
+
Inky.configure do |config|
|
6
|
+
old = config.template_engine
|
7
|
+
spec.run
|
8
|
+
config.template_engine = old
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "default value is :erb" do
|
13
|
+
Inky::Configuration.new.template_engine = :erb
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#configuration=" do
|
17
|
+
it "can set value" do
|
18
|
+
config = Inky::Configuration.new
|
19
|
+
config.template_engine = :haml
|
20
|
+
expect(config.template_engine).to eq(:haml)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#configuration=" do
|
25
|
+
before do
|
26
|
+
Inky.configure do |config|
|
27
|
+
config.template_engine = :haml
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns :haml as configured template_engine" do
|
32
|
+
template_engine = Inky.configuration.template_engine
|
33
|
+
|
34
|
+
expect(template_engine).to be_a(Symbol)
|
35
|
+
expect(template_engine).to eq(:haml)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/inky_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe "Inky#release_the_kraken" do
|
4
|
+
it "works on binary text" do
|
5
|
+
input = '<container/>'.b
|
6
|
+
expected = <<-HTML
|
7
|
+
<table class="container" align="center">
|
8
|
+
<tbody>
|
9
|
+
<tr>
|
10
|
+
<td></td>
|
11
|
+
</tr>
|
12
|
+
</tbody>
|
13
|
+
</table>
|
14
|
+
HTML
|
15
|
+
|
16
|
+
output = Inky::Core.new.release_the_kraken(input)
|
17
|
+
expect_same_html(output, expected)
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,12 +16,12 @@ def reformat_html(html)
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def expect_same_html(input, expected)
|
20
|
+
expect(reformat_html(input)).to eql(reformat_html(expected))
|
21
|
+
end
|
22
|
+
|
19
23
|
def compare(input, expected)
|
20
24
|
inky = Inky::Core.new
|
21
25
|
output = inky.release_the_kraken(input)
|
22
|
-
|
23
|
-
# TODO: Figure out a better way to do html compare in ruby..
|
24
|
-
# this is overly dependent on things like class ordering, making it
|
25
|
-
# fragile
|
26
|
-
expect(reformat_html(output)).to eql(reformat_html(expected))
|
26
|
+
expect_same_html(output, expected)
|
27
27
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<button href="<%= foo -%>">Click me</button>
|
@@ -0,0 +1 @@
|
|
1
|
+
xml.container("Built with builder")
|
@@ -0,0 +1 @@
|
|
1
|
+
Using inky layout
|
@@ -0,0 +1 @@
|
|
1
|
+
<container>Simplistic example</container>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
# require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
# require "active_job/railtie"
|
9
|
+
# require "action_cable/engine"
|
10
|
+
# require "rails/test_unit/railtie"
|
11
|
+
# require "sprockets/railtie"
|
12
|
+
|
13
|
+
Bundler.require(*Rails.groups)
|
14
|
+
require "inky"
|
15
|
+
|
16
|
+
module TestApp
|
17
|
+
class Application < Rails::Application
|
18
|
+
# Settings in config/environments/* take precedence over those specified here.
|
19
|
+
# Application configuration should go into files in config/initializers
|
20
|
+
# -- all .rb files in that directory are automatically loaded.
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
#
|
7
|
+
default: &default
|
8
|
+
adapter: sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: db/development.sqlite3
|
15
|
+
|
16
|
+
# Warning: The database defined as "test" will be erased and
|
17
|
+
# re-generated from your development database when you run "rake".
|
18
|
+
# Do not set this db to the same as development or production.
|
19
|
+
test:
|
20
|
+
<<: *default
|
21
|
+
database: db/test.sqlite3
|
22
|
+
|
23
|
+
production:
|
24
|
+
<<: *default
|
25
|
+
database: db/production.sqlite3
|
@@ -0,0 +1,54 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
|
15
|
+
# Enable/disable caching. By default caching is disabled.
|
16
|
+
if Rails.root.join('tmp/caching-dev.txt').exist?
|
17
|
+
config.action_controller.perform_caching = true
|
18
|
+
|
19
|
+
config.cache_store = :memory_store
|
20
|
+
config.public_file_server.headers = {
|
21
|
+
'Cache-Control' => 'public, max-age=172800'
|
22
|
+
} if config.respond_to? :public_file_server
|
23
|
+
else
|
24
|
+
config.action_controller.perform_caching = false
|
25
|
+
|
26
|
+
config.cache_store = :null_store
|
27
|
+
end
|
28
|
+
|
29
|
+
# Don't care if the mailer can't send.
|
30
|
+
config.action_mailer.raise_delivery_errors = false
|
31
|
+
|
32
|
+
config.action_mailer.perform_caching = false
|
33
|
+
|
34
|
+
# Print deprecation notices to the Rails logger.
|
35
|
+
config.active_support.deprecation = :log
|
36
|
+
|
37
|
+
# Raise an error on page load if there are pending migrations.
|
38
|
+
config.active_record.migration_error = :page_load
|
39
|
+
|
40
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
41
|
+
# This option may cause significant delays in view rendering with a large
|
42
|
+
# number of complex assets.
|
43
|
+
config.assets.debug = true
|
44
|
+
|
45
|
+
# Suppress logger output for asset requests.
|
46
|
+
config.assets.quiet = true
|
47
|
+
|
48
|
+
# Raises error for missing translations
|
49
|
+
# config.action_view.raise_on_missing_translations = true
|
50
|
+
|
51
|
+
# Use an evented file watcher to asynchronously detect changes in source code,
|
52
|
+
# routes, locales, etc. This feature depends on the listen gem.
|
53
|
+
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
54
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# Code is not reloaded between requests.
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Eager load code on boot. This eager loads most of Rails and
|
8
|
+
# your application in memory, allowing both threaded web servers
|
9
|
+
# and those relying on copy on write to perform better.
|
10
|
+
# Rake tasks automatically ignore this option for performance.
|
11
|
+
config.eager_load = true
|
12
|
+
|
13
|
+
# Full error reports are disabled and caching is turned on.
|
14
|
+
config.consider_all_requests_local = false
|
15
|
+
config.action_controller.perform_caching = true
|
16
|
+
|
17
|
+
# Disable serving static files from the `/public` folder by default since
|
18
|
+
# Apache or NGINX already handles this.
|
19
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
20
|
+
|
21
|
+
# Compress JavaScripts and CSS.
|
22
|
+
config.assets.js_compressor = :uglifier
|
23
|
+
# config.assets.css_compressor = :sass
|
24
|
+
|
25
|
+
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
26
|
+
config.assets.compile = false
|
27
|
+
|
28
|
+
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
29
|
+
|
30
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
31
|
+
# config.action_controller.asset_host = 'http://assets.example.com'
|
32
|
+
|
33
|
+
# Specifies the header that your server uses for sending files.
|
34
|
+
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
35
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
36
|
+
|
37
|
+
# Mount Action Cable outside main process or domain
|
38
|
+
# config.action_cable.mount_path = nil
|
39
|
+
# config.action_cable.url = 'wss://example.com/cable'
|
40
|
+
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
|
41
|
+
|
42
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
43
|
+
# config.force_ssl = true
|
44
|
+
|
45
|
+
# Use the lowest log level to ensure availability of diagnostic information
|
46
|
+
# when problems arise.
|
47
|
+
config.log_level = :debug
|
48
|
+
|
49
|
+
# Prepend all log lines with the following tags.
|
50
|
+
config.log_tags = [:request_id]
|
51
|
+
|
52
|
+
# Use a different cache store in production.
|
53
|
+
# config.cache_store = :mem_cache_store
|
54
|
+
|
55
|
+
# Use a real queuing backend for Active Job (and separate queues per environment)
|
56
|
+
# config.active_job.queue_adapter = :resque
|
57
|
+
# config.active_job.queue_name_prefix = "test_app_#{Rails.env}"
|
58
|
+
config.action_mailer.perform_caching = false
|
59
|
+
|
60
|
+
# Ignore bad email addresses and do not raise email delivery errors.
|
61
|
+
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
62
|
+
# config.action_mailer.raise_delivery_errors = false
|
63
|
+
|
64
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
65
|
+
# the I18n.default_locale when a translation cannot be found).
|
66
|
+
config.i18n.fallbacks = true
|
67
|
+
|
68
|
+
# Send deprecation notices to registered listeners.
|
69
|
+
config.active_support.deprecation = :notify
|
70
|
+
|
71
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
72
|
+
config.log_formatter = ::Logger::Formatter.new
|
73
|
+
|
74
|
+
# Use a different logger for distributed setups.
|
75
|
+
# require 'syslog/logger'
|
76
|
+
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
77
|
+
|
78
|
+
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
79
|
+
logger = ActiveSupport::Logger.new(STDOUT)
|
80
|
+
logger.formatter = config.log_formatter
|
81
|
+
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Do not dump schema after migrations.
|
85
|
+
config.active_record.dump_schema_after_migration = false
|
86
|
+
end
|