sibu 0.1.30 → 0.1.31

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: 42e04848ddb67867f8254004f396c25e96f3962f
4
- data.tar.gz: 4e0781f08438129c1e34cdef43f145e26339a0d9
3
+ metadata.gz: a4ce5724416f6921c5a4529d03b9291ffd80876b
4
+ data.tar.gz: f06dee1f7ecd38a5482fe94b7dbe613f59780894
5
5
  SHA512:
6
- metadata.gz: 0a70fa491883f58d8af8f1389c771da93e46ff0f2860792a63dc7273e781e1444c7799815569627cfd6c8fb5aeaf7b223dfdb1c4d366c7d055169f11380f171f
7
- data.tar.gz: 6306180b3ea39f4b603d4f25780298e7fe39dface6509bf62d060135db405782ed668ec4eee747ec4d2b240065531cc59a01a6781761af0600d7811d4a70bdd3
6
+ metadata.gz: 13b0f98002eda8b9fd1af7d8e0fd51f867dada1b1eaa8b1975b6d6b82008d7703fe11aed808a853fb207303482b5eb410367d5e671d70ae0b089d52037b9fc7c
7
+ data.tar.gz: c018e9f2c7c125eb60342a403943d28f9245ea6575e55b63f27e9e273d36d15d25466cc3998774ae98070af4282e67b34cdd58a27ef4eb42a56eb6f218b94e6d
@@ -21,6 +21,7 @@ module Sibu
21
21
  def create
22
22
  @site = Sibu::Site.new(site_params)
23
23
  if @site.save_and_init
24
+ generate_styles
24
25
  redirect_to sites_url, notice: "Le site a bien été créé."
25
26
  else
26
27
  flash.now[:alert] = "Une erreur s'est produite lors de la création du site."
@@ -34,6 +35,9 @@ module Sibu
34
35
 
35
36
  def update
36
37
  if @site.update(site_params)
38
+ if @site.previous_changes.has_key?(:custom_data)
39
+ generate_styles
40
+ end
37
41
  redirect_to (params[:next_page].blank? ? sites_url : params[:next_page]), notice: "Le site a bien été mis à jour."
38
42
  else
39
43
  flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement du site."
@@ -55,5 +59,10 @@ module Sibu
55
59
  def site_params
56
60
  params.require(:site).permit!
57
61
  end
62
+
63
+ def generate_styles
64
+ ds = Sibu::DynamicStyle.new(@site.id)
65
+ ds.compile
66
+ end
58
67
  end
59
68
  end
@@ -0,0 +1,2 @@
1
+ class Sibu::StyleUploader < Shrine
2
+ end
@@ -5,37 +5,38 @@ module Sibu
5
5
 
6
6
  def initialize(site_id)
7
7
  @site = Sibu::Site.find(site_id)
8
- @filename = "_variables"
8
+ @filename = "#{site_id}_#{Time.current.to_i}"
9
9
  @scss_file = File.new(scss_file_path, 'w')
10
- vars_binding = OpenStruct.new(site: @site).instance_eval { binding }
11
- @body = ERB.new(File.read(template_file_path)).result(vars_binding)
10
+ @body = ERB.new(File.read(template_file_path)).result(binding)
12
11
  @env = Rails.application.assets
13
12
  end
14
13
 
15
- # Todo : la compilation semble marcher
16
- # Modifier le fichier cible scss pour que les variables soient directement renseignées (detente.scss.erb)
17
- # Tester la compilation SASS puis mettre en place upload du fichier compilé dans Sibu::Site si ça marche
18
14
  def compile
19
15
  find_or_create_scss
20
16
 
21
17
  begin
22
18
  scss_file.write generate_css
23
19
  scss_file.flush
24
- # site.update(style_url: File.join(site.site_template.path, "#{filename}.css"))
25
- ensure
26
20
  scss_file.close
27
- # File.delete(scss_file)
21
+ css_file_path = scss_file_path.gsub('scss', 'css')
22
+ File.rename(scss_file_path, css_file_path)
23
+ site.update(style: File.new(css_file_path))
24
+ rescue Exception => ex
25
+ logger.error(ex)
26
+ ensure
27
+ File.delete(scss_file_path) if File.exist?(scss_file_path)
28
+ File.delete(css_file_path) if File.exist?(css_file_path)
28
29
  end
29
30
  end
30
31
 
31
32
  private
32
33
 
33
34
  def template_file_path
34
- @template_file_path ||= File.join(Rails.root, 'app', 'assets', 'stylesheets', site.site_template.path, '_template.scss.erb')
35
+ @template_file_path ||= File.join(Rails.root, 'lib', 'assets', '_default_template.scss.erb')
35
36
  end
36
37
 
37
38
  def scss_tmpfile_path
38
- @scss_file_path ||= File.join(Rails.root, 'app', 'assets', 'stylesheets', site.site_template.path)
39
+ @scss_file_path ||= File.join(Rails.root, 'app', 'assets', 'stylesheets', 'templates')
39
40
  FileUtils.mkdir_p(@scss_file_path) unless File.exists?(@scss_file_path)
40
41
  @scss_file_path
41
42
  end
@@ -1,9 +1,10 @@
1
1
  module Sibu
2
2
  class Site < ApplicationRecord
3
+ include StyleUploader::Attachment.new(:style, cache: :styles_cache, store: :styles_store)
3
4
  include Sibu::SectionsConcern
4
5
 
5
6
  store :custom_data, accessors: [:primary_font, :secondary_font, :primary_color, :secondary_color], coder: JSON
6
- store :metadata, accessors: [:analytics_id, :style_url], coder: JSON
7
+ store :metadata, accessors: [:analytics_id], coder: JSON
7
8
 
8
9
  belongs_to :site_template, :class_name => 'Sibu::SiteTemplate'
9
10
  has_many :pages, :class_name => 'Sibu::Page', dependent: :destroy
@@ -11,6 +12,26 @@ module Sibu
11
12
 
12
13
  validates_presence_of :name, :site_template
13
14
 
15
+ def style_url
16
+ style ? style.url : site_template.path
17
+ end
18
+
19
+ def main_color
20
+ primary_color.blank? ? site_template.primary_color : primary_color
21
+ end
22
+
23
+ def alt_color
24
+ secondary_color.blank? ? site_template.secondary_color : secondary_color
25
+ end
26
+
27
+ def main_font
28
+ primary_font.blank? ? site_template.primary_font : primary_font
29
+ end
30
+
31
+ def alt_font
32
+ secondary_font.blank? ? site_template.secondary_font : secondary_font
33
+ end
34
+
14
35
  def section_template(section)
15
36
  "#{site_template.path}/#{section["template"]}"
16
37
  end
@@ -3,6 +3,7 @@ module Sibu
3
3
  store :default_sections, accessors: [:sections], coder: JSON
4
4
  store :default_pages, accessors: [:pages], coder: JSON
5
5
  store :default_templates, accessors: [:templates], coder: JSON
6
+ store :default_styles, accessors: [:primary_font, :secondary_font, :primary_color, :secondary_color], coder: JSON
6
7
 
7
8
  def reference
8
9
  name.parameterize.gsub('-', '_')
@@ -7,15 +7,9 @@
7
7
  <%= javascript_include_tag "#{conf[:javascript]}-edit" %>
8
8
  <%= javascript_include_tag 'sibu/sibu' %>
9
9
  <% if @site %>
10
- <%= stylesheet_link_tag @site.site_template.path, media: "all" %>
10
+ <%= stylesheet_link_tag @site.style_url, media: "all" %>
11
11
  <%= javascript_include_tag "#{@site.site_template.path}-core" %>
12
12
  <% end %>
13
- <% unless @site.primary_font.blank? %>
14
- <%= stylesheet_link_tag "fonts/#{@site.primary_font.downcase}", media: "all" %>
15
- <% end %>
16
- <% unless @site.secondary_font.blank? %>
17
- <%= stylesheet_link_tag "fonts/#{@site.secondary_font.downcase}", media: "all" %>
18
- <% end %>
19
13
  <%= csrf_meta_tags %>
20
14
  <%= yield :styles %>
21
15
  </head>
@@ -7,15 +7,9 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
8
 
9
9
  <% if @site %>
10
- <%= stylesheet_link_tag @site.site_template.path, media: "all" %>
10
+ <%= stylesheet_link_tag @site.style_url, media: "all" %>
11
11
  <%= javascript_include_tag @site.site_template.path %>
12
12
  <% end %>
13
- <% unless @site.primary_font.blank? %>
14
- <%= stylesheet_link_tag "fonts/#{@site.primary_font.downcase}", media: "all" %>
15
- <% end %>
16
- <% unless @site.secondary_font.blank? %>
17
- <%= stylesheet_link_tag "fonts/#{@site.secondary_font.downcase}", media: "all" %>
18
- <% end %>
19
13
  <%= csrf_meta_tags %>
20
14
  <%= yield :styles %>
21
15
  </head>
@@ -66,7 +66,7 @@
66
66
  <%= hidden_field_tag :next_page, @next_page %>
67
67
  <%= f.hidden_field :user_id %>
68
68
  <div class="sibu_actions">
69
- <%= f.submit 'Valider' %>
69
+ <%= f.submit 'Valider', data: {disable: 'Enregistrement en cours...'} %>
70
70
  <%= link_to 'Annuler', :back %>
71
71
  </div>
72
72
  <% end %>
@@ -4,6 +4,8 @@ require "shrine/storage/file_system"
4
4
  Shrine.storages = {
5
5
  cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"),
6
6
  store: Shrine::Storage::FileSystem.new("public", prefix: "uploads/store"),
7
+ styles_cache: Shrine::Storage::FileSystem.new("public", prefix: "stylesheets/cache"),
8
+ styles_store: Shrine::Storage::FileSystem.new("public", prefix: "stylesheets/store")
7
9
  }
8
10
 
9
11
  Shrine.plugin :activerecord
@@ -0,0 +1,5 @@
1
+ class AddStyleDataToSites < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :sibu_sites, :style_data, :text
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddDefaultStylesToTemplates < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :sibu_site_templates, :default_styles, :text
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '0.1.30'
2
+ VERSION = '0.1.31'
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.30
4
+ version: 0.1.31
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-03-01 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -141,6 +141,7 @@ files:
141
141
  - app/mailers/sibu/application_mailer.rb
142
142
  - app/models/concerns/sibu/image_uploader.rb
143
143
  - app/models/concerns/sibu/sections_concern.rb
144
+ - app/models/concerns/sibu/style_uploader.rb
144
145
  - app/models/sibu/application_record.rb
145
146
  - app/models/sibu/dynamic_style.rb
146
147
  - app/models/sibu/image.rb
@@ -205,6 +206,8 @@ files:
205
206
  - db/migrate/20180210181644_add_defaults_to_site_templates.rb
206
207
  - db/migrate/20180214134653_add_fields_to_sites.rb
207
208
  - db/migrate/20180227151519_add_default_templates_to_site_templates.rb
209
+ - db/migrate/20180301121902_add_style_data_to_sites.rb
210
+ - db/migrate/20180301152101_add_default_styles_to_templates.rb
208
211
  - lib/sibu.rb
209
212
  - lib/sibu/engine.rb
210
213
  - lib/sibu/utils.rb