Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettier-plugin-erb

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-erb - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

tests/expressions/expression_as_attribute.html.erb

6

CHANGELOG.md

@@ -5,2 +5,8 @@ # Changelog

## v0.3.0 - 3 June 2021
### Bug fixes
- Fix formatting of expressions inside elements
## v0.2.0 - 25 May 2021

@@ -7,0 +13,0 @@

23

lib/formatter.js

@@ -1,5 +0,5 @@

const { concat, indent, hardline, group } = require('prettier').doc.builders;
const { format } = require('prettier');
const { concat, indent, hardline, group, line } = require('prettier').doc.builders;
const { printDocToString } = require('prettier').doc.printer;
const formatMultilineExpressions = (tokens, options) => {
const formatMultilineExpressions = (tokens, options, embedTextToDoc) => {
return tokens

@@ -21,3 +21,4 @@ .map((token) => ({ ...token }))

if (!formatRaw) {
formattedExpression = format(expression, { ...options, parser: 'ruby' });
formattedExpression = embedTextToDoc(expression, { ...options, parser: 'ruby' });
formattedExpression.parts.pop(); // removes newline at the end
}

@@ -50,3 +51,3 @@ } catch (error) {

if (formattedExpression.trim().match(/\r?\n/)) {
if (typeof formattedExpression === 'string' && formattedExpression.trim().match(/\r?\n/)) {
const formattedMultilineExpression = formattedExpression

@@ -67,5 +68,17 @@ .trim()

);
} else if (typeof formattedExpression === 'object') {
token.content = group(
concat([openingFullTag, indent(concat([line, formattedExpression])), line, closingFullTag])
);
} else {
token.content = group(concat([openingFullTag, ' ', formattedExpression.trim(), ' ', closingFullTag]));
}
// prettier-html-templates can't handle objects in this case, only strings
// TODO: multiline strings aren't formatted correctly, it'd be nice if we could pass the object
// maybe it will be achievable with 2.3 prettier compability
if (token.inElement && typeof token.content === 'object') {
const { formatted } = printDocToString(token.content, { ...options });
token.content = formatted;
}
}

@@ -72,0 +85,0 @@

@@ -22,3 +22,3 @@ const { encodeExpressions, decodeExpressions } = require('prettier-html-templates');

const formattedTokens = formatMultilineExpressions(tokens, options);
const formattedTokens = formatMultilineExpressions(tokens, options, embedTextToDoc);

@@ -25,0 +25,0 @@ const isTextOnlyWithSingleExpression =

{
"name": "prettier-plugin-erb",
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",

@@ -48,3 +48,3 @@ "description": "Prettier plugin for .html.erb files",

"husky": "^6.0.0",
"jest": "^26.6.3",
"jest": "^27.0.3",
"jest-snapshot-serializer-raw": "^1.1.0",

@@ -51,0 +51,0 @@ "lint-staged": "^11.0.0",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc