Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
assets-publisher-for-hanami
Advanced tools
A framework to declare bundles of assets in your Hanami application, compile them into a public folder and add them to your template.
Add this line to your application's Gemfile:
gem 'assets-publisher-for-hanami', '~> 2.0'
And then execute:
$ bundle
Or install it yourself as:
$ gem install assets-publisher-for-hanami
To declare the asset bundles, add this required file to the application.rb file:
require 'cabeza-de-termo/assets-publisher/helpers/helper'
and then add this to your Application class:
module Web
class Application < Hanami::Application
configure do
...
# Define the asset bundles.
# See https://github.com/cabeza-de-termo/assets-library-for-hanami for more details.
CabezaDeTermo::Assets::Library.definition do
# Css
bundle :'bootstrap-css' do
include '/vendor/bootstrap/css/bootstrap.min.css' # include this asset in the bundle
end
# Js
bundle :jquery do
include '/vendor/jquery/jquery-1.11.3.min.js'
end
bundle :'bootstrap-js' do
require :jquery # declare that this bundle depends on the :jquery bundle
include '/vendor/bootstrap/js/bootstrap.min.js'
end
end
# Configure the AssetsPublisher.
CabezaDeTermo::AssetsPublisher::Publisher.configure do
# Where we want to publish the compiled assets
destination_folder 'apps/web/public'
# Where to look for assets
sources << 'apps/web/assets'
# Optional, true by default.
add_timestamps_to_published_assets true
# Optionally uncomment to define custom compilers. You can also use :command_line_compiler
# stylesheets_compiler { CustomCssCompiler.new }
# javascripts_compiler { CustomJsCompiler.new }
end
...
end
end
end
To define the assets to be included in the layout, you can add these methods to your Web::Views::ApplicationLayout class:
module Web
module Views
class ApplicationLayout
...
# Define the stylesheet for this layout
def layout_stylesheets(assets_collector)
assets_collector.require :'bootstrap-css' # include the bundle :'bootstrap-css'
assets_collector.include 'layout/layout.css.scss' # include the asset layout.css.scss'
end
# Define the javascripts for this layout
def layout_javascripts(assets_collector)
assets_collector.require :'bootstrap-js'
end
...
end
end
end
To define the assets to be included in the view, you can add these methods to your Web::Views::SomeView class:
module Web::Views::LandingPage
class Index
include Web::View
# Define the stylesheet for this view
def view_stylesheets(assets_collector)
assets_collector.include 'landing-page/landing-page.css.scss'
end
# Define the javascripts for this view
def view_javascripts(assets_collector)
assets_collector.include 'landing-page/landing-page.js'
end
end
end
To collect the assets, add the AssetsPublisher::Helper to your ApplicationLayout:
module Web
module Views
class ApplicationLayout
include Web::Layout
include CabezaDeTermo::AssetsPublisher::Helper
...
end
end
end
and then use the assets_publisher from your layout template:
doctype html
html
head
meta charset="UTF-8"
meta name="viewport" content="width=device-width, initial-scale=1"
/ This will collect, publish and include all your stylesheets required by your layout and view
== assets_publisher.stylesheets_for self
body
...
/ This will collect, publish and include all your javascripts required by your layout and view
== assets_publisher.javascripts_for self
By default, Publisher uses a TiltCompiler to compile the assets. But you can change that to use a custom one.
If you compile the assets by invoking a command line, there is a command_line_compiler
you can use. In this example we configure the Publisher to use lesscss to compile stylesheets and uglifyjs to compile the javascripts. For this to work you must first install those tools of course.
CabezaDeTermo::AssetsPublisher::Publisher.configure do
...
stylesheets_compiler {
command_line_compiler do |compiler, compilation_job|
files_list = compilation_job.source_filenames.join(' ')
include_folders = compilation_job.source_folders.join(';')
compiler.command_line "lessc",
"--include-path=#{include_folders}",
"--compress",
files_list,
compilation_job.destination_filename
end
}
javascripts_compiler {
command_line_compiler do |compiler, compilation_job|
files_list = compilation_job.source_filenames.join(' ')
compiler.command_line 'uglifyjs', files_list, '--output', compilation_job.destination_filename
end
}
...
end
If you need to write your own compiler, create a class that inherits from CabezaDeTermo::AssetsPublisher::Compiler
require 'cabeza-de-termo/assets-publisher/compilers/compiler'
class CustomCompiler < CabezaDeTermo::AssetsPublisher::Compiler
def compile_assets()
# you can access which files to compile with
compilation_job.source_filenames
# you can access which file to compile to with
compilation_job.destination_filename
# you can access the assets source folders with
compilation_job.source_folders
# do compile the assets
...
end
end
and then configure Publisher to use your custom compiler
CabezaDeTermo::AssetsPublisher::Publisher.configure do
...
stylesheets_compiler { CustomCompiler.new }
# and/or
javascripts_compiler { CustomCompiler.new }
...
end
bundle install
bundle exec rspec
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that assets-publisher-for-hanami demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.