hiccdown 1.1.0 → 1.1.2
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/lib/hiccdown/railtie.rb +54 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf04bfb1f3106def9261f84fc4353ce56b41de39cdcde8a290fac872f10c096a
|
4
|
+
data.tar.gz: 2655d4350fadede3c835bda22b213ad2d015fd971d76e5b5ee0da0e79d64a599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb171437b6462aee24ceeac7c3a9d96356c91f07f27d51c3640b880926ae485a8afa980707a7e11cd0e3b34efb1f8b0cead0524eeec648d865f558ee6a9f842b
|
7
|
+
data.tar.gz: 11facae5d4a755beb3af9ae9fea49ad7cd0c552d6caef859dec3b782d7ef691496aee50fb0ef91b570627d4463dae3803153c01448aa5758242a0795b83abf0f
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Hiccdown
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'hiccdown.action_controller' do
|
4
|
+
ActiveSupport.on_load(:action_controller) do
|
5
|
+
include CustomViewRendering
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module CustomViewRendering
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
alias_method :original_render, :render
|
15
|
+
alias_method :original_default_render, :default_render
|
16
|
+
alias_method :render, :custom_render
|
17
|
+
alias_method :default_render, :custom_default_render
|
18
|
+
end
|
19
|
+
|
20
|
+
def custom_render *args
|
21
|
+
options = args.extract_options!
|
22
|
+
|
23
|
+
# Implicit rendering
|
24
|
+
if options.empty? && args.empty?
|
25
|
+
custom_default_render
|
26
|
+
# Explicit rendering, such as `render :show` or `render action: :show`,
|
27
|
+
# but not partials or files (which would include a /)
|
28
|
+
elsif options.key?(:action) || args.first.is_a?(Symbol) || (args.first.is_a?(String) && !args.first.include?('/'))
|
29
|
+
action_name = options[:action] || args.first.to_s
|
30
|
+
render_helper_method(action_name, options)
|
31
|
+
# Partials, files and all other cases
|
32
|
+
else
|
33
|
+
original_render(*args, options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def custom_default_render
|
38
|
+
render_helper_method(params[:action])
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def render_helper_method action_name, options = {}
|
44
|
+
helper_module = "#{self.class.name.gsub('Controller', '')}Helper".constantize
|
45
|
+
|
46
|
+
if helper_module.instance_methods(false).include?(action_name.to_sym)
|
47
|
+
content = helper_module.instance_method(action_name).bind(view_context).call
|
48
|
+
original_render({ html: Hiccdown::to_html(content).html_safe, layout: true }.merge(options))
|
49
|
+
else
|
50
|
+
original_render({ action: action_name }.merge(options))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiccdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Hackethal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Generates an HTML string from a Hiccup structure and improves Rails views.
|
14
14
|
email: engineering@dennishackethal.com
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/hiccdown.rb
|
20
|
+
- lib/hiccdown/railtie.rb
|
20
21
|
homepage: https://github.com/dchacke/hiccdown
|
21
22
|
licenses:
|
22
23
|
- MIT
|