Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AlchemyCMS/alchemy_cms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 05ddc0dfa97e2087de0ca6cf119b9a8657dafffe
Choose a base ref
..
head repository: AlchemyCMS/alchemy_cms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eb2ffd18daa2df005e00ac9dc1e2b9e5dbd9ee62
Choose a head ref
1 change: 1 addition & 0 deletions lib/generators/alchemy/elements/elements_generator.rb
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ def create_partials
@elements.each do |element|
@element = element
@contents = element["contents"] || []
@ingredients = element["ingredients"] || []
@element_name = element_name(element)
conditional_template "view.html.#{template_engine}", "#{elements_dir}/_#{@element_name}.html.#{template_engine}"
end
9 changes: 9 additions & 0 deletions lib/generators/alchemy/elements/templates/view.html.erb
Original file line number Diff line number Diff line change
@@ -9,6 +9,15 @@
<%%= el.render :<%= content["name"] %> %>
<%- end -%>
<%- end -%>
<%- @ingredients.each do |ingredient| -%>
<%- if @ingredients.length > 1 -%>
<div class="<%= ingredient["role"] %>">
<%%= el.render(:<%= ingredient["role"] %>) %>
</div>
<%- else -%>
<%%= el.render(:<%= ingredient["role"] %>) %>
<%- end -%>
<%- end -%>
<%- if @element['nestable_elements'].present? -%>
<%%= render <%= @element_name %>.nested_elements.available %>
<%- end -%>
9 changes: 9 additions & 0 deletions lib/generators/alchemy/elements/templates/view.html.haml
Original file line number Diff line number Diff line change
@@ -8,6 +8,15 @@
= el.render :<%= content["name"] %>
<%- end -%>
<%- end -%>
<%- @ingredients.each do |ingredient| -%>
<%- if @ingredients.length > 1 -%>
.<%= ingredient["role"] %>
= el.render(:<%= ingredient["role"] %>)
</div>
<%- else -%>
= el.render(:<%= ingredient["role"] %>)
<%- end -%>
<%- end -%>
<%- if @element['nestable_elements'].present? -%>
= render <%= @element_name -%>.nested_elements.available
<%- end -%>
9 changes: 9 additions & 0 deletions lib/generators/alchemy/elements/templates/view.html.slim
Original file line number Diff line number Diff line change
@@ -8,6 +8,15 @@
= el.render :<%= content["name"] %>
<%- end -%>
<%- end -%>
<%- @ingredients.each do |ingredient| -%>
<%- if @ingredients.length > 1 -%>
.<%= ingredient["role"] %>
= el.render(:<%= ingredient["role"] %>)
</div>
<%- else -%>
= el.render(:<%= ingredient["role"] %>)
<%- end -%>
<%- end -%>
<%- if @element['nestable_elements'].present? -%>
= render <%= @element_name -%>.nested_elements.available
<%- end -%>
23 changes: 23 additions & 0 deletions package/src/__tests__/i18n.spec.js
Original file line number Diff line number Diff line change
@@ -15,12 +15,20 @@ describe("translate", () => {
})

describe("if translation is present", () => {
beforeEach(() => {
Alchemy.translations = { en: { help: "Help" } }
})

it("Returns translated string", () => {
expect(translate("help")).toEqual("Help")
})

describe("if key includes a period", () => {
describe("that is translated", () => {
beforeEach(() => {
Alchemy.translations = { en: { formats: { date: "Y-m-d" } } }
})

it("splits into group", () => {
expect(translate("formats.date")).toEqual("Y-m-d")
})
@@ -40,6 +48,10 @@ describe("translate", () => {
})

describe("if replacement is given", () => {
beforeEach(() => {
Alchemy.translations = { en: { allowed_chars: "of %{number} chars" } }
})

it("replaces it", () => {
expect(translate("allowed_chars", 5)).toEqual("of 5 chars")
})
@@ -67,4 +79,15 @@ describe("translate", () => {
spy.mockRestore()
})
})

describe("if Alchemy.translations is not set", () => {
it("Returns passed string and logs a warning", () => {
const spy = jest.spyOn(console, "warn").mockImplementation(() => {})
expect(translate("help")).toEqual("help")
expect(spy.mock.calls).toEqual([
["Translations for locale kl not found!"]
])
spy.mockRestore()
})
})
})
2 changes: 1 addition & 1 deletion package/src/i18n.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ function currentLocale() {

function getTranslations() {
const locale = currentLocale()
const translations = Alchemy.translations[locale]
const translations = Alchemy.translations && Alchemy.translations[locale]

if (translations) {
return translations
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<%- cache(all_you_can_eat_ingredients) do -%>
<%= element_view_for(all_you_can_eat_ingredients) do |el| -%>
<div class="headline">
<%= el.render(:headline) %>
</div>
<div class="text">
<%= el.render(:text) %>
</div>
<div class="picture">
<%= el.render(:picture) %>
</div>
<div class="richtext">
<%= el.render(:richtext) %>
</div>
<div class="select">
<%= el.render(:select) %>
</div>
<div class="boolean">
<%= el.render(:boolean) %>
</div>
<div class="datetime">
<%= el.render(:datetime) %>
</div>
<div class="file">
<%= el.render(:file) %>
</div>
<div class="html">
<%= el.render(:html) %>
</div>
<div class="link">
<%= el.render(:link) %>
</div>
<div class="node">
<%= el.render(:node) %>
</div>
<div class="audio">
<%= el.render(:audio) %>
</div>
<div class="video">
<%= el.render(:video) %>
</div>
<div class="page">
<%= el.render(:page) %>
</div>
<%- end -%>
<%- end -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%- cache(element_with_ingredients) do -%>
<%= element_view_for(element_with_ingredients) do |el| -%>
<div class="headline">
<%= el.render(:headline) %>
</div>
<div class="text">
<%= el.render(:text) %>
</div>
<%- end -%>
<%- end -%>