mirror of
https://github.com/mirego/accent.git
synced 2024-09-11 10:55:28 +03:00
Fix Rails formatter
This commit is contained in:
parent
b457ca6dde
commit
70926dd492
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -4,7 +4,7 @@ on: push
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
services:
|
||||
db:
|
||||
|
@ -17,4 +17,7 @@ if Langue.Formatter.Rails.enabled?() do
|
||||
%Langue.Formatter.ParserResult{entries: entries}
|
||||
end
|
||||
end
|
||||
else
|
||||
defmodule Langue.Formatter.Rails.Parser do
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,20 @@
|
||||
defmodule Langue.Formatter.Rails do
|
||||
use Langue.Formatter,
|
||||
id: "rails_yml",
|
||||
display_name: "Rails YAML",
|
||||
extension: "yml"
|
||||
@enabled Code.ensure_loaded?(:fast_yaml)
|
||||
|
||||
def enabled?, do: Code.ensure_loaded?(:fast_yaml)
|
||||
if @enabled do
|
||||
use Langue.Formatter,
|
||||
id: "rails_yml",
|
||||
display_name: "Rails YAML",
|
||||
extension: "yml",
|
||||
parser: Langue.Formatter.Rails.Parser,
|
||||
serializer: Langue.Formatter.Rails.Serializer
|
||||
else
|
||||
use Langue.Formatter,
|
||||
id: "rails_yml",
|
||||
display_name: "Rails YAML",
|
||||
extension: "yml"
|
||||
end
|
||||
|
||||
def enabled?, do: @enabled
|
||||
def placeholder_regex, do: ~r/%{[^}]*}/
|
||||
end
|
||||
|
@ -19,4 +19,7 @@ if Langue.Formatter.Rails.enabled?() do
|
||||
%Langue.Formatter.SerializerResult{render: render}
|
||||
end
|
||||
end
|
||||
else
|
||||
defmodule Langue.Formatter.Rails.Serializer do
|
||||
end
|
||||
end
|
||||
|
@ -10,6 +10,10 @@ defmodule Langue.Formatter do
|
||||
@callback parse(SerializerResult.t()) :: Langue.Formatter.Parser.result()
|
||||
@callback serialize(ParserResult.t()) :: Langue.Formatter.Serializer.result()
|
||||
|
||||
defmodule Unreachable do
|
||||
defexception [:message]
|
||||
end
|
||||
|
||||
defmacro __using__(opts) do
|
||||
quote do
|
||||
@behaviour Langue.Formatter
|
||||
@ -23,13 +27,23 @@ defmodule Langue.Formatter do
|
||||
if Keyword.has_key?(unquote(opts), :parser) do
|
||||
defdelegate parse(map), to: unquote(opts[:parser])
|
||||
else
|
||||
def parse(_), do: nil
|
||||
def parse(_),
|
||||
do:
|
||||
raise(
|
||||
Langue.Formatter.Unreachable,
|
||||
"#{unquote(opts[:display_name])} could not be used to parse because no `parser` module was used in the formatter definition: #{inspect(unquote(opts))}"
|
||||
)
|
||||
end
|
||||
|
||||
if Keyword.has_key?(unquote(opts), :serializer) do
|
||||
defdelegate serialize(map), to: unquote(opts[:serializer])
|
||||
else
|
||||
def serialize(_), do: nil
|
||||
def serialize(_),
|
||||
do:
|
||||
raise(
|
||||
Langue.Formatter.Unreachable,
|
||||
"#{unquote(opts[:display_name])} could not be used to serialize because no `serializer` module was used in the formatter definition: #{inspect(unquote(opts))}"
|
||||
)
|
||||
end
|
||||
|
||||
defoverridable placeholder_regex: 0, enabled?: 0, parse: 1, serialize: 1
|
||||
|
@ -3,8 +3,8 @@ defmodule Movement.Persisters.Base do
|
||||
|
||||
alias Accent.{Operation, Repo}
|
||||
alias Movement.Mappers.OperationsStats, as: StatMapper
|
||||
alias Movement.Persisters.ProjectStateChangeWorker
|
||||
alias Movement.Migrator
|
||||
alias Movement.Persisters.ProjectStateChangeWorker
|
||||
|
||||
# Inserts operations by batch of 500 to prevent parameters
|
||||
# overflow in database adapter
|
||||
|
@ -7,7 +7,7 @@
|
||||
<label local-class="checkbox">
|
||||
<Input
|
||||
@type="checkbox"
|
||||
@checked={{if (array-includes @events event.value) 'checked'}}
|
||||
@checked={{if (array-includes @events event.value) "checked"}}
|
||||
{{on "change" (fn this.changeEventChecked event.value)}}
|
||||
/>
|
||||
{{t event.label}}
|
||||
|
Loading…
Reference in New Issue
Block a user