Module: WebpackNative::WebpackNativeHelper
- Defined in:
- lib/webpack_native/webpack_native_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#webpack_favicons(*args) ⇒ Object
result: <link rel=“apple-touch-icon” sizes=“180x180” href=“/apple-touch-icon.png”> <link rel=“icon” type=“image/png” sizes=“32x32” href=“/favicon-32x32.png”> <link rel=“icon” type=“image/png” sizes=“16x16” href=“/favicon-16x16.png”> <link rel=“manifest” href=“/site.webmanifest”>.
- #webpack_image_path(image, **options) ⇒ Object
- #webpack_image_tag(image, **options) ⇒ Object
- #webpack_image_url(image, **options) ⇒ Object
- #webpack_javascript_path(asset, **options) ⇒ Object
- #webpack_javascript_tag(asset, **html_options) ⇒ Object
- #webpack_javascript_url(asset, **options) ⇒ Object
- #webpack_stylesheet_path(asset, **options) ⇒ Object
- #webpack_stylesheet_tag(asset, **html_options) ⇒ Object
- #webpack_stylesheet_url(asset, **options) ⇒ Object
Class Method Details
permalink .load_webpack_manifest ⇒ Object
[View source]
121 122 123 124 125 126 127 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 121 def load_webpack_manifest # Set WEBPACK_MANIFEST_PATH to point to the manifest file webpack_manifest_path = Rails.root.join('public', 'webpack_native', 'manifest.json') JSON.parse(File.read(webpack_manifest_path)) rescue Errno::ENOENT fail "The webpack manifest file does not exist. Hint: run webpack command." end |
Instance Method Details
permalink #webpack_favicons(*args) ⇒ Object
result: <link rel=“apple-touch-icon” sizes=“180x180” href=“/apple-touch-icon.png”> <link rel=“icon” type=“image/png” sizes=“32x32” href=“/favicon-32x32.png”> <link rel=“icon” type=“image/png” sizes=“16x16” href=“/favicon-16x16.png”> <link rel=“manifest” href=“/site.webmanifest”>
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 58 def webpack_favicons(*args) = [] args.each do |favicon| filename = File.basename(favicon, ".*") # exclude the extension ext = File.extname(favicon) if ext == '.webmanifest' manifest = favicon = { rel: 'manifest', href: manifest } else mimetypes = { '.png' => 'image/png', '.jpg' => 'image/jpg', '.jpeg' => 'image/jpeg', '.webp' => 'image/webp', '.tiff' => 'image/tiff', '.svg' => 'image/svg+xml', '.ico' => 'image/x-icon' } = { rel: filename == 'apple-touch-icon' ? 'apple-touch-icon' : 'icon', type: mimetypes[ext], href: favicon } sizes = filename[/(.+)?([0-9]{2,3}x[0-9]{2,3})(.+)?/, 2] sizes = '180×180' if filename == 'apple-touch-icon' = .merge({sizes: sizes}) unless sizes.nil? end << tag.link() end return .join.html_safe end |
permalink #webpack_image_path(image, **options) ⇒ Object
[View source]
43 44 45 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 43 def webpack_image_path(image, **) image_path(webpack_native_lookup(image), **) end |
permalink #webpack_image_tag(image, **options) ⇒ Object
[View source]
35 36 37 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 35 def webpack_image_tag(image, **) image_tag(webpack_native_lookup(image), **) end |
permalink #webpack_image_url(image, **options) ⇒ Object
[View source]
39 40 41 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 39 def webpack_image_url(image, **) image_url(webpack_native_lookup(image), **) end |
permalink #webpack_javascript_path(asset, **options) ⇒ Object
[View source]
31 32 33 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 31 def webpack_javascript_path(asset, **) path_to_asset(webpack_native_lookup("#{asset.gsub('.js', '')}.js"), ) end |
permalink #webpack_javascript_tag(asset, **html_options) ⇒ Object
[View source]
19 20 21 22 23 24 25 26 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 19 def webpack_javascript_tag(asset, **) = .merge( type: "text/javascript", src: webpack_javascript_path(asset) ) content_tag("script".freeze, nil, ).html_safe # or tag.script(html_options).html_safe end |
permalink #webpack_javascript_url(asset, **options) ⇒ Object
[View source]
28 29 30 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 28 def webpack_javascript_url(asset, **) url_to_asset(webpack_native_lookup("#{asset.gsub('.js', '')}.js"), ) end |
permalink #webpack_stylesheet_path(asset, **options) ⇒ Object
[View source]
11 12 13 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 11 def webpack_stylesheet_path(asset, **) path_to_asset(webpack_native_lookup("#{asset.gsub('.css', '')}.css"), ) end |
permalink #webpack_stylesheet_tag(asset, **html_options) ⇒ Object
[View source]
3 4 5 6 7 8 9 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 3 def webpack_stylesheet_tag(asset, **) = .merge( href: webpack_stylesheet_path(asset), rel: "stylesheet" ) tag.link().html_safe end |
permalink #webpack_stylesheet_url(asset, **options) ⇒ Object
[View source]
15 16 17 |
# File 'lib/webpack_native/webpack_native_helper.rb', line 15 def webpack_stylesheet_url(asset, **) url_to_asset(webpack_native_lookup("#{asset.gsub('.css', '')}.css"), ) end |