sibu 0.1.25 → 0.1.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/sibu/images_controller.rb +22 -2
- data/app/controllers/sibu/pages_controller.rb +8 -7
- data/app/helpers/sibu/pages_helper.rb +3 -4
- data/app/models/concerns/sibu/sections_concern.rb +13 -7
- data/app/models/sibu/image.rb +4 -0
- data/app/models/sibu/page.rb +4 -0
- data/app/models/sibu/site.rb +1 -0
- data/app/models/sibu/site_template.rb +6 -0
- data/app/views/sibu/images/_form.html.erb +17 -2
- data/app/views/sibu/pages/_form.html.erb +1 -1
- data/app/views/sibu/pages/_media_edit_panel.html.erb +4 -2
- data/app/views/sibu/pages/_new_section_panel.html.erb +8 -6
- data/app/views/sibu/pages/edit_element.js.erb +1 -0
- data/app/views/sibu/pages/new_section.js.erb +1 -1
- data/app/views/sibu/sites/_form.html.erb +31 -5
- data/db/migrate/20180227151519_add_default_templates_to_site_templates.rb +5 -0
- data/lib/sibu/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae660a877d92fc982f3f013404a4afd4d79e46de
|
4
|
+
data.tar.gz: 5b4221c6178eb1b5cb4b497bfef8801e989c77a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b954bf098086c3b9ac081be9538a5e565f93908ade83b99dd6dfb72f01e2efdb3a8f806d2bd8be10176a558723be7fbb3f3afc17893dcaa980e8d1ca414017cf
|
7
|
+
data.tar.gz: 2a9d4af45641c0db7453ae2439c944df92a577cb401c3ed588ac8bf523801102b4ca190ee5cc0a8f278ac40ba0e50c6d6b58f2ed0c70016e9592ead171414b2c
|
@@ -3,6 +3,7 @@ require_dependency "sibu/application_controller"
|
|
3
3
|
module Sibu
|
4
4
|
class ImagesController < ApplicationController
|
5
5
|
before_action :set_site, only: [:index, :new, :create, :edit]
|
6
|
+
before_action :set_edition_context, only: [:new, :create]
|
6
7
|
|
7
8
|
def index
|
8
9
|
@images = Sibu::Image.where(site_id: params[:site_id])
|
@@ -10,13 +11,24 @@ module Sibu
|
|
10
11
|
|
11
12
|
def new
|
12
13
|
@image = Sibu::Image.new(site_id: @site.id)
|
13
|
-
@page_id = params[:page_id]
|
14
14
|
end
|
15
15
|
|
16
16
|
def create
|
17
17
|
@image = Sibu::Image.new(image_params)
|
18
18
|
if @image.save
|
19
|
-
|
19
|
+
if @page_id && @section_id && @element_id && @size
|
20
|
+
page = Sibu::Page.find(@page_id)
|
21
|
+
ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
|
22
|
+
elt = page.update_element(*ids, {"id" => @img_id, "src" => @image.file_url(@size.to_sym), "alt" => @image.alt})
|
23
|
+
if elt.nil?
|
24
|
+
msg = {alert: "Une erreur s'est produite lors de la mise à jour de l'image."}
|
25
|
+
else
|
26
|
+
msg = {notice: "L'image a bien été mise à jour."}
|
27
|
+
end
|
28
|
+
redirect_to site_page_edit_content_path(@site.id, page.id), msg
|
29
|
+
else
|
30
|
+
redirect_to site_images_url(@image.site_id), notice: "L'image a bien été téléchargée."
|
31
|
+
end
|
20
32
|
else
|
21
33
|
flash.now[:alert] = "Une erreur s'est produite lors du téléchargement de l'image."
|
22
34
|
render :new
|
@@ -41,6 +53,14 @@ module Sibu
|
|
41
53
|
@site = Sibu::Site.find(params[:site_id])
|
42
54
|
end
|
43
55
|
|
56
|
+
def set_edition_context
|
57
|
+
@page_id = params[:page_id]
|
58
|
+
@section_id = params[:section_id]
|
59
|
+
@element_id = params[:element_id]
|
60
|
+
@img_id = params[:img_id]
|
61
|
+
@size = params[:size]
|
62
|
+
end
|
63
|
+
|
44
64
|
def image_params
|
45
65
|
params.require(:image).permit!
|
46
66
|
end
|
@@ -97,15 +97,16 @@ module Sibu
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def new_section
|
100
|
+
page = Sibu::Page.find(params[:id])
|
101
|
+
@page = Page.new(id: page.id, sections: [])
|
102
|
+
@site = Sibu::Site.includes(:pages).find(page.site_id)
|
100
103
|
@after = params[:after]
|
101
104
|
@links = @site.pages_path_by_id
|
102
|
-
|
103
|
-
@
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
{"id" => "col1", "elements" => [{"id" => "row1"}, {"id" => "row2"}]},
|
108
|
-
]}
|
105
|
+
|
106
|
+
@site.site_template.available_templates.each do |t|
|
107
|
+
template_defaults = @site.site_template.templates ? (@site.site_template.templates[t["template"]] || {}) : {}
|
108
|
+
@page.sections << template_defaults.merge(t).to_h
|
109
|
+
end
|
109
110
|
end
|
110
111
|
|
111
112
|
def create_section
|
@@ -12,8 +12,7 @@ module Sibu
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def sections_templates
|
15
|
-
|
16
|
-
.map {|f| f[1..-1].gsub('.html.erb', '')}.select {|f| f != 'site'}.map {|f| {"id" => "sibu_template_#{f}", "template" => f}}
|
15
|
+
@site.site_template.available_templates
|
17
16
|
end
|
18
17
|
|
19
18
|
def page_languages
|
@@ -21,7 +20,7 @@ module Sibu
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def site_images
|
24
|
-
|
23
|
+
Sibu::Image.shared + @site.images
|
25
24
|
end
|
26
25
|
|
27
26
|
def available_links
|
@@ -59,7 +58,7 @@ module Sibu
|
|
59
58
|
|
60
59
|
def elements(id = nil)
|
61
60
|
items = id ? select_element(id)["elements"] : @sb_entity.find_or_init(*@sb_section)["elements"]
|
62
|
-
items.blank? ? [{"id" => "#{
|
61
|
+
items.blank? ? [{"id" => "el#{Time.current.to_i}"}] : items
|
63
62
|
end
|
64
63
|
|
65
64
|
def img(elt, opts = {})
|
@@ -52,7 +52,7 @@ module Sibu
|
|
52
52
|
siblings = find_or_init(*ids)["elements"]
|
53
53
|
ref_index = siblings.index {|s| s["id"] == element_id}
|
54
54
|
new_elt = siblings[ref_index].deep_dup
|
55
|
-
new_elt["id"] =
|
55
|
+
new_elt["id"] = "cl#{Time.current.to_i}"
|
56
56
|
siblings.insert(ref_index + 1, new_elt)
|
57
57
|
save ? new_elt : nil
|
58
58
|
end
|
@@ -73,23 +73,29 @@ module Sibu
|
|
73
73
|
siblings = elements(*ids)
|
74
74
|
parent_elt = siblings[siblings.index {|s| s["id"] == element_id}]
|
75
75
|
if parent_elt["elements"].blank?
|
76
|
-
parent_elt["elements"] = [{"id" => "#{
|
76
|
+
parent_elt["elements"] = [{"id" => "cl#{Time.current.to_i}"}]
|
77
77
|
else
|
78
|
-
parent_elt["elements"] << [{"id" => "#{
|
78
|
+
parent_elt["elements"] << [{"id" => "cl#{Time.current.to_i}"}]
|
79
79
|
end
|
80
80
|
save
|
81
81
|
end
|
82
82
|
|
83
83
|
def create_section(*ids, after, new_section)
|
84
|
-
new_section["id"] = "#{
|
84
|
+
new_section["id"] = "cs#{Time.current.to_i}"
|
85
85
|
if ids.length == 1
|
86
86
|
parent = sections
|
87
87
|
else
|
88
88
|
parent = find_or_init(*ids[0..-2])["elements"]
|
89
89
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
if new_section["template"].blank?
|
91
|
+
nil
|
92
|
+
else
|
93
|
+
template_defaults = site_template.templates ? site_template.templates[new_section["template"]] : {}
|
94
|
+
sec = template_defaults.merge(new_section)
|
95
|
+
ref_pos = parent.index {|s| s["id"] == ids.last}
|
96
|
+
parent.insert(after.to_s == 'true' ? ref_pos + 1 : ref_pos, sec)
|
97
|
+
sec if save
|
98
|
+
end
|
93
99
|
end
|
94
100
|
|
95
101
|
def delete_section(*ids)
|
data/app/models/sibu/image.rb
CHANGED
data/app/models/sibu/page.rb
CHANGED
data/app/models/sibu/site.rb
CHANGED
@@ -3,6 +3,7 @@ module Sibu
|
|
3
3
|
include Sibu::SectionsConcern
|
4
4
|
|
5
5
|
store :custom_data, accessors: [:primary_font, :secondary_font, :primary_color, :secondary_color], coder: JSON
|
6
|
+
store :metadata, accessors: [:analytics_id]
|
6
7
|
|
7
8
|
belongs_to :site_template, :class_name => 'Sibu::SiteTemplate'
|
8
9
|
has_many :pages, :class_name => 'Sibu::Page', dependent: :destroy
|
@@ -2,9 +2,15 @@ module Sibu
|
|
2
2
|
class SiteTemplate < ApplicationRecord
|
3
3
|
store :default_sections, accessors: [:sections], coder: JSON
|
4
4
|
store :default_pages, accessors: [:pages], coder: JSON
|
5
|
+
store :default_templates, accessors: [:templates], coder: JSON
|
5
6
|
|
6
7
|
def reference
|
7
8
|
name.parameterize.gsub('-', '_')
|
8
9
|
end
|
10
|
+
|
11
|
+
def available_templates
|
12
|
+
Dir.glob(File.join(Rails.root, "app/views/shared/#{path}/*.erb")).map {|f| f.split('/').last}
|
13
|
+
.map {|f| f[1..-1].gsub('.html.erb', '')}.select {|f| f != 'site'}.map {|f| {"id" => "sibu_template_#{f}", "template" => f}}
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
@@ -1,10 +1,25 @@
|
|
1
1
|
<%= form_for([@site, @image]) do |f| %>
|
2
2
|
<div class="sibu_field">
|
3
|
-
<%= f.
|
4
|
-
|
3
|
+
<%= f.label :file, "Sélection de l'image" %>
|
4
|
+
<div>
|
5
|
+
<%= f.hidden_field :file, value: @image.cached_file_data %>
|
6
|
+
<%= f.file_field :file %>
|
7
|
+
<small>Sélectionnez une image à télécharger depuis votre ordinateur</small>
|
8
|
+
</div>
|
9
|
+
</div>
|
10
|
+
<div class="sibu_field">
|
11
|
+
<%= f.label :alt, "Légende / texte alternatif" %>
|
12
|
+
<div>
|
13
|
+
<%= f.text_field :alt %>
|
14
|
+
<small>Renseignez un texte décrivant l'image</small>
|
15
|
+
</div>
|
5
16
|
</div>
|
6
17
|
<%= f.hidden_field :site_id %>
|
7
18
|
<%= hidden_field_tag :page_id, @page_id %>
|
19
|
+
<%= hidden_field_tag :element_id, @element_id %>
|
20
|
+
<%= hidden_field_tag :section_id, @section_id %>
|
21
|
+
<%= hidden_field_tag :img_id, @img_id %>
|
22
|
+
<%= hidden_field_tag :size, @size %>
|
8
23
|
<div class="sibu_actions">
|
9
24
|
<%= f.submit 'Valider' %>
|
10
25
|
<%= link_to 'Annuler', :back %>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<div class="sibu_field">
|
17
17
|
<%= f.label :language, "Langue" %>
|
18
18
|
<div>
|
19
|
-
<%= f.select(:language, page_languages
|
19
|
+
<%= f.select(:language, page_languages) %>
|
20
20
|
<small>La langue d'affichage de la page</small>
|
21
21
|
</div>
|
22
22
|
</div>
|
@@ -4,10 +4,12 @@
|
|
4
4
|
<div class="sibu_edit_form">
|
5
5
|
<%= form_tag(update_element_site_page_path(@site.id, @page.id), method: :patch, remote: true) do |f| %>
|
6
6
|
<div class="sibu_select_images sibu_field">
|
7
|
-
<p>Sélectionnez ou <%= link_to 'téléchargez', new_site_image_path(@site.id, page_id: @page.id
|
7
|
+
<p>Sélectionnez ou <%= link_to 'téléchargez', new_site_image_path(@site.id, page_id: @page.id, section_id: @section_id,
|
8
|
+
element_id: @element_id, img_id: @element["id"], size: @size) %> une image</p>
|
8
9
|
<% site_images.each do |image| %>
|
9
10
|
<div class="sibu_image" data-img-id="<%= image.id %>">
|
10
|
-
<%= image_tag image.file_url(:small), class: (@element["src"] == image.file_url(@size) ? 'selected' : ''),
|
11
|
+
<%= image_tag image.file_url(:small), class: (@element["src"] == image.file_url(@size) ? 'selected' : ''),
|
12
|
+
data: {src: image.file_url(@size), alt: image.alt} %>
|
11
13
|
</div>
|
12
14
|
<% end %>
|
13
15
|
</div>
|
@@ -3,12 +3,14 @@
|
|
3
3
|
<div id="edit_msg"></div>
|
4
4
|
</div>
|
5
5
|
<div>
|
6
|
-
<div
|
7
|
-
|
8
|
-
|
9
|
-
<%=
|
10
|
-
|
11
|
-
|
6
|
+
<div class="sibu_sections sibu_site_content">
|
7
|
+
<div id="<%= "#{@site.site_template.reference}_sections" %>">
|
8
|
+
<% sections_templates.each do |st| %>
|
9
|
+
<div data-sb-template="<%= st["template"] %>">
|
10
|
+
<%= render "shared/#{@site.section_template(st)}", sec: st %>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
12
14
|
</div>
|
13
15
|
<%= form_tag(create_section_site_page_path(@site.id, @page.id), method: :post, remote: true) do |f| %>
|
14
16
|
<%= hidden_field_tag 'section[template]', '' %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
var sectionsPanel = $("#sections_panel");
|
2
2
|
sectionsPanel.html("");
|
3
3
|
sectionsPanel.html("<%= j(render 'new_section_panel') %>");
|
4
|
-
var sections = sectionsPanel.find(".sibu_sections
|
4
|
+
var sections = sectionsPanel.find(".sibu_sections [data-sb-template]");
|
5
5
|
sections.click(function() {
|
6
6
|
if(!$(this).hasClass('selected')) {
|
7
7
|
sections.removeClass('selected');
|
@@ -1,22 +1,40 @@
|
|
1
1
|
<%= form_for @site do |f| %>
|
2
2
|
<div class="sibu_field">
|
3
3
|
<%= f.label :name, 'Nom du site' %>
|
4
|
-
|
4
|
+
<div>
|
5
|
+
<%= f.text_field :name, placeholder: "Ex : Site de l'Hôtel du Lac" %>
|
6
|
+
<small>Libellé utilisé dans l'outil d'administration (non utilisé dans le site)</small>
|
7
|
+
</div>
|
5
8
|
</div>
|
6
9
|
<div class="sibu_field">
|
7
10
|
<%= f.label :name, 'Nom de domaine' %>
|
8
|
-
|
11
|
+
<div>
|
12
|
+
<%= f.text_field :domain, placeholder: "Ex : www.monsite.com (utilisé lors de la mise en ligne du site)" %>
|
13
|
+
<small>Renseignez le nom de domaine de votre site (utile uniquement lors de la publication)</small>
|
14
|
+
</div>
|
9
15
|
</div>
|
10
16
|
<div class="sibu_field">
|
11
17
|
<%= f.label :site_template_id, 'Modèle' %>
|
12
|
-
|
18
|
+
<div>
|
19
|
+
<%= f.collection_select(:site_template_id, Sibu::SiteTemplate.all, :id, :name, {prompt: 'Sélectionnez un modèle de site'}, disabled: @site.persisted?) %>
|
20
|
+
<small>Choisissez le gabarit qui servira de modèle pour votre site (non modifiable après création)</small>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
<div class="sibu_field">
|
24
|
+
<%= f.label :analytics_id, "Statistiques d'audience" %>
|
25
|
+
<div>
|
26
|
+
<%= f.text_field :analytics_id, placeholder: "UA-XXXXXX" %>
|
27
|
+
<small>Renseignez l'identifiant Google Analytics pour suivre les statistiques d'audience du site</small>
|
28
|
+
</div>
|
13
29
|
</div>
|
30
|
+
<% if @next_page %>
|
14
31
|
<div class="sibu_field sibu_colors">
|
15
32
|
<%= f.label :primary_color, 'Couleur principale' %>
|
16
33
|
<div>
|
17
34
|
<% primary_colors.each do |c| %>
|
18
35
|
<span class="sibu_color <%= 'selected' if f.object.primary_color == c %>" data-color="<%= c %>" style="background-color: <%= c %>;"></span>
|
19
36
|
<% end %>
|
37
|
+
<small>Couleur principale appliquée au modèle choisi</small>
|
20
38
|
</div>
|
21
39
|
<%= f.hidden_field :primary_color %>
|
22
40
|
</div>
|
@@ -26,17 +44,25 @@
|
|
26
44
|
<% secondary_colors.each do |c| %>
|
27
45
|
<span class="sibu_color <%= 'selected' if f.object.secondary_color == c %>" data-color="<%= c %>" style="background-color: <%= c %>;"></span>
|
28
46
|
<% end %>
|
47
|
+
<small>Couleur secondaire appliquée au modèle choisi</small>
|
29
48
|
</div>
|
30
49
|
<%= f.hidden_field :secondary_color %>
|
31
50
|
</div>
|
32
51
|
<div class="sibu_field">
|
33
52
|
<%= f.label :name, 'Police de caractères (titres)' %>
|
34
|
-
|
53
|
+
<div>
|
54
|
+
<%= f.select :primary_font, primary_fonts, {prompt: 'Police par défaut'} %>
|
55
|
+
<small>Police de caractère utilisée pour les titres du modèle choisi</small>
|
56
|
+
</div>
|
35
57
|
</div>
|
36
58
|
<div class="sibu_field">
|
37
59
|
<%= f.label :name, 'Police de caractères (corps)' %>
|
38
|
-
|
60
|
+
<div>
|
61
|
+
<%= f.select :secondary_font, secondary_fonts, {prompt: 'Police par défaut'} %>
|
62
|
+
<small>Police de caractère utilisée pour les corps de texte du modèle choisi</small>
|
63
|
+
</div>
|
39
64
|
</div>
|
65
|
+
<% end %>
|
40
66
|
<%= hidden_field_tag :next_page, @next_page %>
|
41
67
|
<%= f.hidden_field :user_id %>
|
42
68
|
<div class="sibu_actions">
|
data/lib/sibu/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sibu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Baptiste Vilain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- db/migrate/20180208125024_rename_image_data_column.rb
|
185
185
|
- db/migrate/20180210181644_add_defaults_to_site_templates.rb
|
186
186
|
- db/migrate/20180214134653_add_fields_to_sites.rb
|
187
|
+
- db/migrate/20180227151519_add_default_templates_to_site_templates.rb
|
187
188
|
- lib/sibu.rb
|
188
189
|
- lib/sibu/engine.rb
|
189
190
|
- lib/sibu/utils.rb
|