sibu 0.1.25 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 916acca3e25a345d957ff420f7fa164992dedeb0
4
- data.tar.gz: 8c5332f2f016ad73c8f864c8b9ae4804bf1e7c13
3
+ metadata.gz: ae660a877d92fc982f3f013404a4afd4d79e46de
4
+ data.tar.gz: 5b4221c6178eb1b5cb4b497bfef8801e989c77a3
5
5
  SHA512:
6
- metadata.gz: aad71cc6b158cf274e9058530b7f01db7ee842bbf172cf6847ae4279e0de1a09253417597120bd3a1ecba9652897e44b4656df7223498bed869ee4ae5e6feb69
7
- data.tar.gz: 69febad581a88ab80a797d5cf9f1d6ff2b7ab0925fb9a3ef31ade3b88c57a53f4ea0df9144bbb20ef3cd4d251a35a7ef984fbe07eb32874a28043ecf7a1198b9
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
- redirect_to (params[:page_id].blank? ? site_images_url(@image.site_id) : site_page_edit_content_path(@site.id, params[:page_id])), notice: "L'image a bien été téléchargée."
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
- @page.sections << {"id" => "sibu_template_free_text", "elements" => [{"id" => "paragraph0"}]}
103
- @page.sections << {"id" => "sibu_template_gallery",
104
- "elements" => [{"id" => "slide0"}, {"id" => "slide1"}, {"id" => "slide2"}]}
105
- @page.sections << {"id" => "sibu_template_table", "elements" => [
106
- {"id" => "col0", "elements" => [{"id" => "row1"}, {"id" => "row2"}]},
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
- Dir.glob(File.join(Rails.root, "app/views/shared/#{@site.site_template.path}/*.erb")).map {|f| f.split('/').last}
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
- @site.images + Sibu::Image.shared
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" => "#{@sb_section.last}*"}] : items
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"] = element_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" => "#{element_id}*"}]
76
+ parent_elt["elements"] = [{"id" => "cl#{Time.current.to_i}"}]
77
77
  else
78
- parent_elt["elements"] << [{"id" => "#{parent_elt["elements"].last["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"] = "#{new_section["template"]}-#{Time.current.to_i}"
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
- ref_pos = parent.index {|s| s["id"] == ids.last}
91
- parent.insert(after.to_s == 'true' ? ref_pos + 1 : ref_pos, new_section)
92
- save ? new_section : nil
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)
@@ -4,6 +4,10 @@ module Sibu
4
4
 
5
5
  belongs_to :site, :class_name => 'Sibu::Site', optional: true
6
6
 
7
+ store :metadata, accessors: [:alt], coder: JSON
8
+
9
+ validates_presence_of :file_data
10
+
7
11
  def self.shared
8
12
  where(site_id: nil)
9
13
  end
@@ -21,5 +21,9 @@ module Sibu
21
21
  def update_path
22
22
  self.path = name.parameterize if self.path.blank? && name != 'Accueil'
23
23
  end
24
+
25
+ def site_template
26
+ site.site_template
27
+ end
24
28
  end
25
29
  end
@@ -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.hidden_field :file, value: @image.cached_file_data %>
4
- <%= f.file_field :file %>
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, {prompt: 'Sélectionnez une langue'}) %>
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) %> une image</p>
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' : ''), data: {src: image.file_url(@size)} %>
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 id="<%= "#{@site.site_template.reference}_sections" %>" class="sibu_sections sibu_site_content">
7
- <% sections_templates.each do |st| %>
8
- <div data-sb-template="<%= st["template"] %>">
9
- <%= render "shared/#{@site.section_template(st)}", sec: st %>
10
- </div>
11
- <% end %>
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]', '' %>
@@ -25,6 +25,7 @@ editPanel.html("");
25
25
  images.removeClass('selected');
26
26
  $(this).addClass('selected');
27
27
  $("#element_src").val($(this).data("src"));
28
+ $("#element_alt").val($(this).data("alt"));
28
29
  }
29
30
  });
30
31
  <% when 'link' %>
@@ -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
- <%= f.text_field :name, placeholder: "Ex : Site de l'Hôtel du Lac" %>
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
- <%= f.text_field :domain, placeholder: "Ex : www.monsite.com (utilisé lors de la mise en ligne du site)" %>
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
- <%= f.collection_select(:site_template_id, Sibu::SiteTemplate.all, :id, :name, {prompt: 'Sélectionnez un modèle de site'}, disabled: @site.persisted?) %>
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
- <%= f.select :primary_font, primary_fonts, {prompt: 'Police par défaut'} %>
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
- <%= f.select :secondary_font, secondary_fonts, {prompt: 'Police par défaut'} %>
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">
@@ -0,0 +1,5 @@
1
+ class AddDefaultTemplatesToSiteTemplates < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :sibu_site_templates, :default_templates, :text
4
+ end
5
+ end
data/lib/sibu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '0.1.25'
2
+ VERSION = '0.1.26'
3
3
  end
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.25
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-27 00:00:00.000000000 Z
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