diff --git a/examples/simple-jsbeautifyrc/blade/expected/test.blade.php b/examples/simple-jsbeautifyrc/blade/expected/test.blade.php new file mode 100644 index 0000000..69d537e --- /dev/null +++ b/examples/simple-jsbeautifyrc/blade/expected/test.blade.php @@ -0,0 +1,32 @@ + + + + App Name - @yield('title') + + + + @section('sidebar') This is the {{ $mater }} sidebar. + @show + +
+ @yield('content') +
+ + @component('alert') + @slot('title') Forbidden + @endslot + Whoops! Something went wrong! + @endcomponent + + @foreach ($users as $user) + @if ($user->type == 1) + @continue + @endif +
  • {{ $user->name }}
  • + @if ($user->number == 5) + @break + @endif + @endforeach + + + diff --git a/examples/simple-jsbeautifyrc/blade/original/test.blade.php b/examples/simple-jsbeautifyrc/blade/original/test.blade.php new file mode 100644 index 0000000..5fa50bc --- /dev/null +++ b/examples/simple-jsbeautifyrc/blade/original/test.blade.php @@ -0,0 +1,31 @@ + + +App Name - @yield('title') + + +@section('sidebar') +This is the {{ $mater }} sidebar. +@show + +
    +@yield('content') +
    + +@component('alert') +@slot('title') +Forbidden +@endslot +Whoops! Something went wrong! +@endcomponent + +@foreach ($users as $user) +@if ($user->type == 1) +@continue +@endif +
  • {{ $user->name }}
  • +@if ($user->number == 5) +@break +@endif +@endforeach + + diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 4310acd..bca9711 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -44,7 +44,7 @@ describe "BeautifyLanguages", -> # Activate all of the languages allLanguages = [ - "c", "clojure", "coffee-script", "css", "csharp", "d", + "blade", "c", "clojure", "coffee-script", "css", "csharp", "d", "gfm", "go", "html", "html-swig", "java", "javascript", "json", "less", "lua", "marko", "mustache", "objective-c", "perl", "php", "python", "ruby", "sass", "sql", diff --git a/src/beautifiers/js-beautify.coffee b/src/beautifiers/js-beautify.coffee index 6a178e5..1894a64 100644 --- a/src/beautifiers/js-beautify.coffee +++ b/src/beautifiers/js-beautify.coffee @@ -6,6 +6,7 @@ module.exports = class JSBeautify extends Beautifier link: "https://github.com/beautify-web/js-beautify" options: { + Blade: true HTML: true XML: true Handlebars: true @@ -51,6 +52,16 @@ module.exports = class JSBeautify extends Beautifier beautifyCSS = require("js-beautify").css text = beautifyCSS(text, options) resolve text + when "Blade" + beautifyHTML = require("js-beautify").html + # pre script (Workaround) + text = text.replace(/\@(?!yield)([^\n\s]*)/ig, "") + text = beautifyHTML(text, options) + # post script (Workaround) + text = text.replace(//ig, "@$1") + text = text.replace(/\(\ \'/ig, "('") + @debug("Beautified HTML: #{text}") + resolve text else reject(new Error("Unknown language for JS Beautify: "+language)) catch err diff --git a/src/languages/blade.coffee b/src/languages/blade.coffee new file mode 100644 index 0000000..f35d929 --- /dev/null +++ b/src/languages/blade.coffee @@ -0,0 +1,22 @@ +module.exports = { + + name: "Blade" + namespace: "blade" + fallback: ["html", "php"] + + ### + Supported Grammars + ### + grammars: [ + "Blade" + ] + + ### + Supported extensions + ### + extensions: [ + "blade.php" + ] + + options: [] +} diff --git a/src/languages/index.coffee b/src/languages/index.coffee index e0df65c..cfd305d 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -15,6 +15,7 @@ module.exports = class Languages "apex" "arduino" "bash" + "blade" "c-sharp" "c" "clojure"