sibu 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f546bd4008bbe0847d6328ae30fd34f0feb06f8
4
- data.tar.gz: 9734a6b7db39f25dd1a9de72feeafe551d49d302
3
+ metadata.gz: 55c6e2a83ee5222226abadce0270913620fc0be7
4
+ data.tar.gz: 838423c80a797ef3c8a5f4022d94f23b6c8e880a
5
5
  SHA512:
6
- metadata.gz: d3b58626ea0c86f6384d4cd7207733333077bf3bde3fc46c1729718658745c34ac0cf4497e5396f681e33df754195c7141048ff1248db26309e7da9b37e31563
7
- data.tar.gz: 84cac6c6ffe0dd30976f762d3d14c05fc3862eea70c51da8edce32e744bedfd989667fb676aa8f5905419616be61c215d3bc668b9be30e238ac73209922fc7b4
6
+ metadata.gz: 8e638a83f6b58bafa9bf0cd6a17850586f538f1dd3b4909849924ba47687bc6970bb29982768f4f2d20d5468c32094953a4562fea2a132f86c2c075c3e2c48e0
7
+ data.tar.gz: a596fe89724f5f320f239ba844538d6e9556e14a67059b18af7de73c13c1c4fa1a335399721a9b97ec252650d36f97aa985a88d938a66ef8006e2377ab259a5a
@@ -9,6 +9,8 @@
9
9
 
10
10
  sb-edit {
11
11
  position: relative;
12
+ display: inherit;
13
+ width: 100%;
12
14
  }
13
15
 
14
16
  sb-edit div.sb-overlay {
@@ -2,7 +2,7 @@ require_dependency "sibu/application_controller"
2
2
 
3
3
  module Sibu
4
4
  class ImagesController < ApplicationController
5
- before_action :set_site, only: [:index, :new]
5
+ before_action :set_site, only: [:index, :new, :create, :edit]
6
6
 
7
7
  def index
8
8
  @images = Sibu::Image.where(site_id: params[:site_id])
@@ -10,12 +10,13 @@ module Sibu
10
10
 
11
11
  def new
12
12
  @image = Sibu::Image.new(site_id: @site.id)
13
+ @page_id = params[:page_id]
13
14
  end
14
15
 
15
16
  def create
16
17
  @image = Sibu::Image.new(image_params)
17
18
  if @image.save
18
- redirect_to site_images_url(@image.site_id), notice: "L'image a bien été téléchargée."
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
20
  else
20
21
  flash.now[:alert] = "Une erreur s'est produite lors du téléchargement de l'image."
21
22
  render :new
@@ -28,7 +29,7 @@ module Sibu
28
29
  def edit
29
30
  end
30
31
 
31
- def updateé
32
+ def update
32
33
  end
33
34
 
34
35
  def destroy
@@ -2,10 +2,11 @@ require_dependency "sibu/application_controller"
2
2
 
3
3
  module Sibu
4
4
  class PagesController < ApplicationController
5
- before_action :set_page, only: [:edit, :update, :destroy, :edit_element, :update_element, :edit_section,
6
- :clone_section, :delete_section]
5
+ before_action :set_page, only: [:edit, :update, :destroy, :edit_element, :update_element, :clone_element,
6
+ :delete_element, :edit_section, :clone_section, :delete_section]
7
7
  before_action :set_site, only: [:index, :new]
8
- before_action :set_edit_context, only: [:edit_element, :update_element, :clone_section, :delete_section]
8
+ before_action :set_edit_context, only: [:edit_element, :update_element, :clone_element, :delete_element,
9
+ :clone_section, :delete_section]
9
10
  skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
10
11
 
11
12
  def index
@@ -78,6 +79,14 @@ module Sibu
78
79
  @updated = @entity.update_element(*@section_id.split('|'), element_params)
79
80
  end
80
81
 
82
+ def clone_element
83
+ @cloned = @entity.clone_element(*@section_id.split('|'), @element_id)
84
+ end
85
+
86
+ def delete_element
87
+ @deleted = @entity.delete_element(*@section_id.split('|'), @element_id)
88
+ end
89
+
81
90
  def edit_section
82
91
  end
83
92
 
@@ -85,12 +94,10 @@ module Sibu
85
94
  end
86
95
 
87
96
  def clone_section
88
- @section_id = params[:section_id]
89
97
  @cloned = @entity.clone_section(*@section_id.split('|'))
90
98
  end
91
99
 
92
100
  def delete_section
93
- @section_id = params[:section_id]
94
101
  @deleted = @entity.delete_section(*@section_id.split('|'))
95
102
  end
96
103
 
@@ -19,7 +19,7 @@ module Sibu
19
19
 
20
20
  [:h1, :h2, :h3, :h4, :h5, :h6, :p, :span, :div].each do |t|
21
21
  define_method(t) do |elt, html_opts = {}|
22
- defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt,"text" => "Texte à modifier"}
22
+ defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "text" => "Texte à modifier"}
23
23
  content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
24
24
  html_opts.merge!({class: "sb-#{t} #{html_opts[:class]}", data: {id: elt.is_a?(Hash) ? elt["id"] : elt}}) if action_name != 'show'
25
25
  content_tag(t, raw(content["text"]).html_safe, html_opts)
@@ -38,7 +38,11 @@ module Sibu
38
38
  @sb_entity = @site
39
39
  @sb_section = sub_id ? [id, sub_id] : [id]
40
40
  if block_given?
41
- "<sb-edit data-id='#{@sb_section.join('|')}' data-entity='site'>#{capture(self, &block)}</sb-edit>".html_safe
41
+ if action_name != 'show'
42
+ "<sb-edit data-id='#{@sb_section.join('|')}' data-entity='site'>#{capture(self, &block)}</sb-edit>".html_safe
43
+ else
44
+ capture(self, &block)
45
+ end
42
46
  else
43
47
  self
44
48
  end
@@ -47,7 +51,11 @@ module Sibu
47
51
  def section(id, sub_id = nil, &block)
48
52
  @sb_entity = @page
49
53
  @sb_section = sub_id ? [id, sub_id] : [id]
50
- "<sb-edit data-id='#{@sb_section.join('|')}' data-entity='page' data-duplicate='#{!sub_id.nil?}'>#{capture(self, &block)}</sb-edit>".html_safe
54
+ if action_name != 'show'
55
+ "<sb-edit data-id='#{@sb_section.join('|')}' data-entity='page' data-duplicate='#{!sub_id.nil?}'>#{capture(self, &block)}</sb-edit>".html_safe
56
+ else
57
+ capture(self, &block)
58
+ end
51
59
  end
52
60
 
53
61
  # def site_sections(id, &block)
@@ -88,20 +96,61 @@ module Sibu
88
96
  end
89
97
  end
90
98
 
91
- def img(elt, html_opts = {})
99
+ def img(elt, opts = {})
100
+ wrapper = opts.delete(:wrapper)
92
101
  defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "src" => "/default.jpg"}
93
102
  content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
94
- html_opts.merge!({class: "sb-img #{html_opts[:class]}", data: {id: elt.is_a?(Hash) ? elt["id"] : elt}}) if action_name != 'show'
95
- content_tag(:img, nil, content.except("id").merge(html_opts))
103
+ opts.merge!({class: "sb-img #{opts[:class]}", data: {id: elt.is_a?(Hash) ? elt["id"] : elt}}) if action_name != 'show'
104
+ wrapper ? content_tag(wrapper, content_tag(:img, nil, content.except("id")), opts) : content_tag(:img, nil, content.except("id").merge(opts))
96
105
  end
97
106
 
98
- def bg_img(elt, html_opts = {})
99
- defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "src" => "/default.jpg"}
100
- content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
101
- html_opts.merge!({class: "sb-img #{html_opts[:class]}", data: {id: elt.is_a?(Hash) ? elt["id"] : elt}}) if action_name != 'show'
102
- content_tag(:div, content_tag(:img, nil, content.except("id")), html_opts)
107
+ # Note : see ActionView::OutputBuffer
108
+ def sb_page
109
+ @sb_entity = @page
110
+ self
111
+ end
112
+ alias page sb_page
113
+
114
+ def sb_site
115
+ @sb_entity = @site
116
+ self
117
+ end
118
+ alias site sb_site
119
+
120
+ def repeat(&block)
121
+ ((action_name != 'show' ? "<sb-edit data-id='#{@sb_section}' data-entity='#{@sb_entity == @site ? 'site' : 'page'}'>" : '') +
122
+ @sb_entity.section(@sb_section).map {|elt| capture(elt, &block)}.join('') +
123
+ (action_name != 'show' ? "</sb-edit>" : '')).html_safe
124
+ end
125
+
126
+ def secsion(id)
127
+ @sb_section = id
128
+ if block_given?
129
+ if current_action != 'show'
130
+ "<sb-edit data-id='#{@sb_section}' data-entity='#{@sb_entity == @site ? 'site' : 'page'}'>#{capture(self, &block)}</sb-edit>".html_safe
131
+ else
132
+ capture(self, &block)
133
+ end
134
+ else
135
+ self
136
+ end
103
137
  end
104
138
 
139
+ def secsions(id)
140
+
141
+ end
142
+
143
+ def elts
144
+
145
+ end
146
+
147
+ # def bg_img(elt, html_opts = {})
148
+ # defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "src" => "/default.jpg"}
149
+ # content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
150
+ # html_opts.merge!({class: "sb-img #{html_opts[:class]}", data: {id: elt.is_a?(Hash) ? elt["id"] : elt}}) if action_name != 'show'
151
+ # content_tag(:div, content_tag(:img, nil, content.except("id")), html_opts)
152
+ # end
153
+
105
154
  def link(elt, html_opts = {}, &block)
106
155
  defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "value" => "", "text" => "Nouveau lien"}
107
156
  content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
@@ -1,4 +1,19 @@
1
1
  module Sibu
2
2
  module SitesHelper
3
+ def primary_colors
4
+ Rails.application.config.sibu[:primary_colors]
5
+ end
6
+
7
+ def secondary_colors
8
+ Rails.application.config.sibu[:secondary_colors]
9
+ end
10
+
11
+ def primary_fonts
12
+ Rails.application.config.sibu[:primary_fonts]
13
+ end
14
+
15
+ def secondary_fonts
16
+ Rails.application.config.sibu[:secondary_fonts]
17
+ end
3
18
  end
4
19
  end
@@ -60,6 +60,22 @@ module Sibu
60
60
  value if save
61
61
  end
62
62
 
63
+ def clone_element(*ids, element_id)
64
+ siblings = section(*ids)
65
+ ref_index = siblings.index {|s| s["id"] == element_id}
66
+ new_elt = siblings[ref_index].deep_dup
67
+ new_elt["id"] = element_id + '§'
68
+ siblings.insert(ref_index + 1, new_elt)
69
+ save ? new_elt : nil
70
+ end
71
+
72
+ def delete_element(*ids, element_id)
73
+ siblings = section(*ids)
74
+ ref_index = siblings.index {|s| s["id"] == element_id}
75
+ siblings.delete_at(ref_index)
76
+ save
77
+ end
78
+
63
79
  def clone_section(*ids)
64
80
  siblings = section(ids.first)
65
81
  ref_index = siblings.index {|s| s["id"] == ids.last}
@@ -2,6 +2,8 @@ module Sibu
2
2
  class Site < ApplicationRecord
3
3
  include Sibu::SectionsConcern
4
4
 
5
+ store :custom_data, accessors: [:primary_font, :secondary_font, :primary_color, :secondary_color], coder: JSON
6
+
5
7
  belongs_to :site_template, :class_name => 'Sibu::SiteTemplate'
6
8
  has_many :pages, :class_name => 'Sibu::Page', dependent: :destroy
7
9
  has_many :images, :class_name => 'Sibu::Image', dependent: :destroy
@@ -14,5 +14,6 @@
14
14
  </div>
15
15
  <% end %>
16
16
  <% end %>
17
+ <%= yield :scripts %>
17
18
  </body>
18
19
  </html>
@@ -11,6 +11,7 @@
11
11
  <%= javascript_include_tag "#{@site.site_template.path}-core" %>
12
12
  <% end %>
13
13
  <%= csrf_meta_tags %>
14
+ <%= yield :styles %>
14
15
  </head>
15
16
  <body>
16
17
  <% [:top_panel, :side_panel, :content_panel, :bottom_panel].each do |panel| %>
@@ -11,6 +11,7 @@
11
11
  <%= javascript_include_tag @site.site_template.path %>
12
12
  <% end %>
13
13
  <%= csrf_meta_tags %>
14
+ <%= yield :styles %>
14
15
  </head>
15
16
  <body>
16
17
 
@@ -4,6 +4,7 @@
4
4
  <%= f.file_field :file %>
5
5
  </div>
6
6
  <%= f.hidden_field :site_id %>
7
+ <%= hidden_field_tag :page_id, @page_id %>
7
8
  <div class="sibu_actions">
8
9
  <%= f.submit 'Valider' %>
9
10
  <%= link_to 'Annuler', :back %>
@@ -0,0 +1,23 @@
1
+ <% content_for :styles do %>
2
+ <style>
3
+ <% unless @site.primary_color.blank? %>
4
+ :not(.sibu_panel) [class*='bg--primary'] {
5
+ background-color: <%= @site.primary_color %> !important;
6
+ }
7
+
8
+ :not(.sibu_panel) [class *='txt--primary'] {
9
+ color: <%= @site.primary_color %> !important;
10
+ }
11
+ <% end %>
12
+
13
+ <% unless @site.secondary_color.blank? %>
14
+ :not(.sibu_panel) [class*='bg--success'] {
15
+ background-color: <%= @site.secondary_color %> !important;
16
+ }
17
+
18
+ :not(.sibu_panel) [class *='txt--success'] {
19
+ color: <%= @site.secondary_color %> !important;
20
+ }
21
+ <% end %>
22
+ </style>
23
+ <% end %>
@@ -1,9 +1,10 @@
1
1
  <h2>Modifier l'image</h2>
2
+
2
3
  <div id="edit_msg"></div>
3
4
  <div class="sibu_edit_form">
4
5
  <%= form_tag(update_element_site_page_path(@site.id, @page.id), method: :patch, remote: true) do |f| %>
5
6
  <div class="sibu_select_images sibu_field">
6
- <p>Sélectionnez ou <%= link_to 'téléchargez', new_site_image_path(@site.id) %> une image</p>
7
+ <p>Sélectionnez ou <%= link_to 'téléchargez', new_site_image_path(@site.id, page_id: @page.id) %> une image</p>
7
8
  <% @site.images.each do |image| %>
8
9
  <div class="sibu_image">
9
10
  <%= image_tag image.file_url(:small) %>
@@ -0,0 +1,9 @@
1
+ <% if @cloned.nil? %>
2
+ $("#edit_panel #edit_msg").html("<p class='sibu_alert'>Une erreur s'est produite lors de l'enregistrement.</p>");
3
+ <% else %>
4
+ $("#edit_panel").slideUp();
5
+ var clonedElt = $("sb-edit[data-id='<%= @section_id %>']").find("[data-id='<%= @element_id %>']").first();
6
+ var newElt = clonedElt.clone();
7
+ newElt.data("id", "<%= @cloned["id"] %>");
8
+ clonedElt.after(newElt);
9
+ <% end %>
@@ -1,3 +1,4 @@
1
+ <%= render 'custom_styles' %>
1
2
  <div class="edit_content">
2
3
  <%= render "shared/#{@site.site_template.path}/site" %>
3
4
  </div>
@@ -4,7 +4,7 @@ editPanel.html("");
4
4
  <% text_value = @element["text"] || 'Texte à modifier' %>
5
5
  editPanel.html("<%= j(render 'text_edit_panel') %>");
6
6
  var editorElt = editPanel.find("trix-editor")[0];
7
- editorElt.editor.loadHTML("<%= raw(text_value.gsub("\n", "<br/>")) %>");
7
+ editorElt.editor.loadHTML("<%= j(raw(text_value.gsub("\n", "<br/>"))) %>");
8
8
  <% elsif @content_type == 'media' %>
9
9
  editPanel.html("<%= j(render 'media_edit_panel') %>");
10
10
  editPanel.find(".sibu_image img").click(function() {
@@ -15,5 +15,4 @@ editPanel.html("");
15
15
  editPanel.html("<%= j(render 'link_edit_panel') %>");
16
16
  <% end %>
17
17
 
18
-
19
18
  editPanel.slideDown("fast");
@@ -17,7 +17,7 @@
17
17
  <% @pages.each do |p| %>
18
18
  <tr>
19
19
  <td><%= p.name %></td>
20
- <td><%= p.template %></td>
20
+ <td><%= t "sibu.templates.#{p.template}" %></td>
21
21
  <td><%= p.path %></td>
22
22
  <td><%= l p.updated_at %></td>
23
23
  <td colspan="2">
@@ -1 +1,2 @@
1
+ <%= render 'custom_styles' %>
1
2
  <%= render "shared/#{@site.site_template.path}/site" %>
@@ -3,13 +3,62 @@
3
3
  <%= f.label :name, 'Nom du site' %>
4
4
  <%= f.text_field :name, placeholder: "Ex : Site de l'Hôtel du Lac" %>
5
5
  </div>
6
+ <div class="sibu_field">
7
+ <%= 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)" %>
9
+ </div>
6
10
  <div class="sibu_field">
7
11
  <%= f.label :site_template_id, 'Modèle' %>
8
- <%= f.collection_select(:site_template_id, Sibu::SiteTemplate.all, :id, :name, {prompt: 'Sélectionnez un modèle de site'}) %>
12
+ <%= f.collection_select(:site_template_id, Sibu::SiteTemplate.all, :id, :name, {prompt: 'Sélectionnez un modèle de site'}, disabled: @site.persisted?) %>
13
+ </div>
14
+ <div class="sibu_field sibu_colors">
15
+ <%= f.label :primary_color, 'Couleur principale' %>
16
+ <div>
17
+ <% primary_colors.each do |c| %>
18
+ <span class="sibu_color <%= 'selected' if f.object.primary_color == c %>" data-color="<%= c %>" style="background-color: <%= c %>;"></span>
19
+ <% end %>
20
+ </div>
21
+ <%= f.hidden_field :primary_color %>
22
+ </div>
23
+ <div class="sibu_field sibu_colors">
24
+ <%= f.label :secondary_color, 'Couleur secondaire' %>
25
+ <div>
26
+ <% secondary_colors.each do |c| %>
27
+ <span class="sibu_color <%= 'selected' if f.object.secondary_color == c %>" data-color="<%= c %>" style="background-color: <%= c %>;"></span>
28
+ <% end %>
29
+ </div>
30
+ <%= f.hidden_field :secondary_color %>
31
+ </div>
32
+ <div class="sibu_field">
33
+ <%= f.label :name, 'Police de caractères (titres)' %>
34
+
35
+ </div>
36
+ <div class="sibu_field">
37
+ <%= f.label :name, 'Police de caractères (corps)' %>
38
+
9
39
  </div>
10
40
  <%= f.hidden_field :user_id %>
11
41
  <div class="sibu_actions">
12
42
  <%= f.submit 'Valider' %>
13
43
  <%= link_to 'Annuler', :back %>
14
44
  </div>
45
+ <% end %>
46
+
47
+ <% content_for :scripts do %>
48
+ <script>
49
+ $(".sibu_colors").each(function () {
50
+ var colors = $(this).find(".sibu_color");
51
+ var input = $(this).find("input");
52
+ colors.click(function () {
53
+ if($(this).hasClass('selected')) {
54
+ $(this).removeClass("selected");
55
+ input.val('');
56
+ } else {
57
+ colors.removeClass("selected");
58
+ $(this).addClass('selected');
59
+ input.val($(this).data("color"));
60
+ }
61
+ });
62
+ });
63
+ </script>
15
64
  <% end %>
data/config/routes.rb CHANGED
@@ -10,6 +10,8 @@ Sibu::Engine.routes.draw do
10
10
  get :edit_element, on: :member
11
11
  get :edit_section, on: :member
12
12
  patch 'update_element', on: :member
13
+ post 'clone_element', on: :member
14
+ delete 'delete_element', on: :member
13
15
  patch 'update_section', on: :member
14
16
  post 'clone_section', on: :member
15
17
  delete 'delete_section', on: :member
@@ -0,0 +1,5 @@
1
+ class AddFieldsToSites < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :sibu_sites, :custom_data, :text
4
+ end
5
+ end
data/lib/sibu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '0.1.12'
2
+ VERSION = '0.1.13'
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.12
4
+ version: 0.1.13
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-13 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -147,10 +147,12 @@ files:
147
147
  - app/views/sibu/images/index.html.erb
148
148
  - app/views/sibu/images/new.html.erb
149
149
  - app/views/sibu/images/show.html.erb
150
+ - app/views/sibu/pages/_custom_styles.html.erb
150
151
  - app/views/sibu/pages/_form.html.erb
151
152
  - app/views/sibu/pages/_link_edit_panel.html.erb
152
153
  - app/views/sibu/pages/_media_edit_panel.html.erb
153
154
  - app/views/sibu/pages/_text_edit_panel.html.erb
155
+ - app/views/sibu/pages/clone_element.js.erb
154
156
  - app/views/sibu/pages/clone_section.js.erb
155
157
  - app/views/sibu/pages/delete_section.js.erb
156
158
  - app/views/sibu/pages/destroy.html.erb
@@ -182,6 +184,7 @@ files:
182
184
  - db/migrate/20180208082317_rename_images_user_id_to_site_id.rb
183
185
  - db/migrate/20180208125024_rename_image_data_column.rb
184
186
  - db/migrate/20180210181644_add_defaults_to_site_templates.rb
187
+ - db/migrate/20180214134653_add_fields_to_sites.rb
185
188
  - lib/sibu.rb
186
189
  - lib/sibu/engine.rb
187
190
  - lib/sibu/version.rb