Skip to content

Commit

Permalink
Merge pull request #53 from Platoniq/main
Browse files Browse the repository at this point in the history
Merge branch 'main' into 'release/0.27-stable'
  • Loading branch information
fblupi authored Sep 9, 2024
2 parents 896b49d + 1221cce commit 6de8c0d
Show file tree
Hide file tree
Showing 34 changed files with 726 additions and 55 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: "[CI] Test"

on:
push:
branches:
- main
pull_request:

env:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ And then execute:

```bash
bundle
bundle exec rails decidim_alternative_landing:webpacker:install
```

Depending on your Decidim version, choose the corresponding version to ensure compatibility:

| Alternative Landing version | Compatible Decidim versions |
|-----------------------------|-----------------------------|
| 0.4.x | 0.27.x |
| 0.3.x | 0.25.x, 0.26.x |
| 0.2.x | 0.24.x |

Expand Down
16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require "fileutils"
desc "Generates a dummy app for testing"
task test_app: "decidim:generate_external_test_app" do
ENV["RAILS_ENV"] = "test"
fix_babel_config("spec/decidim_dummy_app")
override_webpacker_config_files("spec/decidim_dummy_app")
end

Expand All @@ -21,6 +22,20 @@ def seed_db(path)
end
end

# Temporary fix to overcome the issue with babel plugin updates, see:
# https://github.com/decidim/decidim/pull/10916
def fix_babel_config(path)
Dir.chdir(path) do
babel_config = "#{Dir.pwd}/babel.config.json"
File.delete(babel_config) if File.exist?(babel_config)
FileUtils.cp("#{__dir__}/babel.config.json", Dir.pwd)

# Temporary fix to overcome the issue with sass-embedded, see:
# https://github.com/decidim/decidim/pull/11074
system("npm i sass-embedded@~1.62.0")
end
end

desc "Generates a development app."
task :development_app do
Bundler.with_original_env do
Expand All @@ -35,6 +50,7 @@ task :development_app do
)
end

fix_babel_config("development_app")
seed_db("development_app")
override_webpacker_config_files("development_app")
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ def meeting_path(meeting)

def meetings
@meetings ||= Meetings::Meeting.upcoming.where(
component: meeting_component
component: component || components
).limit(meetings_to_show).order(start_time: :asc)
end

private

def manifest_name
"meetings"
end

# A MD5 hash of model attributes because is needed because
# it ensures the cache version value will always be the same size
def cache_hash
Expand All @@ -40,10 +44,6 @@ def cache_hash
hash.join("/")
end

def meeting_component
@meeting_component ||= (Component.find_by(id: model.settings.component_id) || Component.where(manifest_name: "meetings"))
end

def meetings_to_show
model.settings.count || 3
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<%= settings_fields.translated :text_field, :link_text, label: t(".link_text") %>
<%= settings_fields.translated :text_field, :link_url, label: t(".link_url") %>
<%= settings_fields.number_field :count, label: t(".count") %>

<% if component %>
<p class="callout secondary">
<%= t(".info", component: translated_attribute(component.name), space: translated_attribute(component.participatory_space.title)) %>
</p>
<% end %>

<%= settings_fields.select :component_id, available_components("meetings") %>
<%= settings_fields.select :component_id, available_components %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module ContentBlocks
class AlternativeUpcomingMeetingsSettingsFormCell < BaseCell
alias form model

def component
@component ||= Decidim::Component.find_by(id: form.object.settings.try(:component_id))
def manifest_name
"meetings"
end
end
end
Expand Down
34 changes: 31 additions & 3 deletions app/cells/decidim/alternative_landing/content_blocks/base_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,40 @@ def participatory_spaces
].flatten.compact
end

def available_components(manifest_name)
Decidim::Component.published.where(participatory_space: participatory_spaces, manifest_name: manifest_name).map do |component|
def available_components
@available_components ||= components.where(manifest_name: manifest_name).map do |component|
["#{translated_attribute(component.name)} (#{translated_attribute(component.participatory_space.title)})", component.id]
end.unshift [t(".all"), nil]
end

def component
@component ||= Decidim::Component.find_by(id: form.object.settings.try(:component_id))
@component ||= components.find_by(id: (defined?(form) ? form.object : model).settings.try(:component_id))
end

def components
@components ||= Decidim::Component.where(participatory_space: participatory_spaces)
end

def manifest_name
raise NotImplementedError
end

def colors
model.settings.to_h.select { |k, _v| k.match?(/color_/) }
end

def opacities
model.settings.to_h.select { |k, _v| k.match?(/opacity_/) }
end

def color_keys
form.object.settings.to_h.keys.grep(/color_/)
end

def opacity_keys
form.object.settings.to_h.keys.grep(/opacity_/)
end

# Renders a view with the customizable CSS variables in two flavours:
# 1. as a hexadecimal valid CSS color (ie: #ff0000)
# 2. as a disassembled RGB components (ie: 255,0,0)
Expand All @@ -54,6 +70,12 @@ def color_keys
#
# background-color: rgba(var(--primary-rgb), 0.5)
def css
colors_css + opacities_css
end

private

def colors_css
colors.each.map do |k, v|
if v.match?(/^#[0-9a-fA-F]{6}$/)
"--#{k}: #{v};--#{k}-rgb: #{v[1..2].hex},#{v[3..4].hex},#{v[5..6].hex};"
Expand All @@ -62,6 +84,12 @@ def css
end
end.join
end

def opacities_css
opacities.each.map do |k, v|
"--#{k}: #{v};"
end.join
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
</div>
<% end %>
</div>
<div style="display: flex; gap: 1rem;">
<% opacity_keys.each do |opacity_key| %>
<div style="flex: auto;">
<%= settings_fields.number_field opacity_key, label: t(".#{opacity_key}"), step: 0.1, min: 0, max: 1 %>
</div>
<% end %>
</div>
<% end %>
<% form.fields_for :images, form.object.images do |images_fields| %>
<%= images_fields.upload :background_image, label: t(".background_image") %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
</div>
<% end %>
</div>
<div style="display: flex; gap: 1rem;">
<% opacity_keys.each do |opacity_key| %>
<div style="flex: auto;">
<%= settings_fields.number_field opacity_key, label: t(".#{opacity_key}"), step: 0.1, min: 0, max: 1 %>
</div>
<% end %>
</div>
<% end %>
<% form.fields_for :images, form.object.images do |images_fields| %>
<%= images_fields.upload :background_image, label: t(".background_image") %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ def post_path(post)

def posts
@posts ||= Blogs::Post.where(
component: blog_components.find_by(id: model.settings.component_id) || blog_components
component: component || components
).limit(posts_to_show).order(created_at: :desc)
end

private

def manifest_name
"blogs"
end

# A MD5 hash of model attributes because is needed because
# it ensures the cache version value will always be the same size
def cache_hash
Expand All @@ -39,10 +43,6 @@ def cache_hash
hash.join("/")
end

def blog_components
@blog_components ||= Component.published.where(manifest_name: "blogs")
end

def posts_to_show
model.settings.count || 3
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<%= settings_fields.translated :text_field, :link_text, label: t(".link_text") %>
<%= settings_fields.translated :text_field, :link_url, label: t(".link_url") %>
<%= settings_fields.number_field :count, label: t(".count") %>

<% if component %>
<p class="callout secondary">
<%= t(".info", component: translated_attribute(component.name), space: translated_attribute(component.participatory_space.title)) %>
</p>
<% end %>

<%= settings_fields.select :component_id, available_components("blogs") %>
<%= settings_fields.select :component_id, available_components %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module AlternativeLanding
module ContentBlocks
class LatestBlogPostsSettingsFormCell < BaseCell
alias form model

def manifest_name
"blogs"
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<% 1.upto(3) do |item_number| %>
<div class="stack-item">
<div class="stack-image">
<%= image_tag image(item_number) %>
<%= image_tag image(item_number) if image(item_number).present? %>
</div>
<div class="stack-body">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ class TilesCell < BaseCell
def translated_title(item_number = nil)
return translated_attribute(model.settings.title) if item_number.blank?

translated_attribute(model.settings.send("title_#{item_number}"))
if translated_url(item_number).blank?
translated_attribute(model.settings.send("title_#{item_number}"))
else
link_to translated_attribute(model.settings.send("title_#{item_number}")), translated_url(item_number)
end
end

def translated_body(item_number)
translated_attribute(model.settings.send("body_#{item_number}"))
end

def translated_url(item_number)
translated_attribute(model.settings.send("link_url_#{item_number}"))
end

def background_image(item_number)
model.images_container.attached_uploader("background_image_#{item_number}".to_sym).path(variant: :landscape)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div class="large-3 p-xs">
<%= settings_fields.translated :text_field, :"title_#{item_number}", label: t(".title_n", item_number: item_number) %>
<%= settings_fields.translated :text_area, :"body_#{item_number}", rows: 3, label: t(".body_n", item_number: item_number) %>
<%= settings_fields.translated :text_field, :"link_url_#{item_number}", label: t(".link_url_n", item_number: item_number) %>
</div>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@import "stylesheets/decidim/alternative_landing/content_blocks/variables";

@mixin cover-background-image($color) {
@mixin cover-background-image($color, $opacity) {
background-size: cover;
background-position: center;
background-blend-mode: luminosity;
background-color: $color;
background-color: rgba($color, $opacity);
min-height: 100vh;
}

Expand All @@ -16,12 +16,12 @@
}

.cover-full {
color: var(--color_text);
color: rgba(var(--color_text-rgb), var(--opacity_text));

@include cover-background-image(var(--color_background_image));
@include cover-background-image(var(--color_background_image-rgb), var(--opacity_background_image));

.cover-text {
background-color: rgba(var(--color_background_text-rgb), 0.7);
background-color: rgba(var(--color_background_text-rgb), var(--opacity_background_text));
padding: $gap * 2;
}
}
Expand All @@ -33,7 +33,7 @@
.cover-image {
grid-column: 2;

@include cover-background-image(var(--color_background_image));
@include cover-background-image(var(--color_background_image-rgb), var(--opacity_background_image));
}

.cover-text {
Expand All @@ -54,7 +54,7 @@
}

.navbar.transparent {
background-color: rgba(var(--color_navbar-rgb), 0.3);
background-color: rgba(var(--color_navbar-rgb), var(--opacity_navbar));
position: relative;
margin-bottom: -50px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
max-width: 20em;
background: $alternative-color-1;
padding: $gap;

h2 {
a {
color: $header-color;
}
}
}

&-heading {
Expand Down
25 changes: 25 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"presets": [
[
"@babel/preset-env", {
"forceAllTransforms": true,
"useBuiltIns": "entry",
"corejs": 3,
"modules": false
}
],
["@babel/preset-react"]
],
"plugins": [
"@babel/plugin-transform-classes",
[
"@babel/plugin-transform-runtime",
{
"helpers": false,
"regenerator": true,
"corejs": false
}
],
["@babel/plugin-transform-regenerator", { "async": false }]
]
}
Loading

0 comments on commit 6de8c0d

Please sign in to comment.