bamboo_legals 0.0.6 → 0.1.1

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bamboo_legals +10 -0
  3. data/lib/bamboo_legals.rb +36 -0
  4. data/lib/generators/controller.rb +21 -0
  5. data/lib/generators/manual.rb +47 -0
  6. data/lib/generators/migration.rb +21 -0
  7. data/lib/generators/model.rb +20 -0
  8. data/lib/generators/routes.rb +28 -0
  9. data/lib/generators/views.rb +37 -0
  10. data/lib/templates/monolingual/admin_legals_controller.txt +51 -0
  11. data/lib/templates/monolingual/admin_views/_form.txt +33 -0
  12. data/lib/templates/monolingual/admin_views/_legal.txt +15 -0
  13. data/lib/templates/monolingual/admin_views/edit.txt +15 -0
  14. data/lib/templates/monolingual/admin_views/index.txt +31 -0
  15. data/lib/templates/monolingual/admin_views/new.txt +15 -0
  16. data/lib/templates/monolingual/legal.txt +26 -0
  17. data/lib/templates/monolingual/legals_controller.txt +5 -0
  18. data/lib/templates/monolingual/views/_index.txt +7 -0
  19. data/lib/templates/monolingual/views/show.txt +12 -0
  20. data/lib/templates/multilingual/admin_legals_controller.txt +56 -0
  21. data/lib/templates/multilingual/admin_views/_form.txt +43 -0
  22. data/lib/templates/multilingual/admin_views/edit.txt +13 -0
  23. data/lib/templates/multilingual/admin_views/index.txt +43 -0
  24. data/lib/templates/multilingual/admin_views/new.txt +13 -0
  25. data/lib/templates/multilingual/legal.txt +32 -0
  26. data/lib/templates/multilingual/legal_translation.txt +18 -0
  27. data/lib/templates/multilingual/legals_controller.txt +5 -0
  28. data/lib/templates/multilingual/views/_footer_legal.txt +6 -0
  29. data/lib/templates/multilingual/views/show.html.txt +17 -0
  30. metadata +32 -5
  31. data/bin/add_bamboo_legals +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 928113bb4a58d8824f2148c11de321a9d082a448
4
- data.tar.gz: 497357ac00a05c577aaacaef87bf68b5e25d33e5
3
+ metadata.gz: 45b78cfdc8962581456cb3f8cd0c968c1a3a6de9
4
+ data.tar.gz: b91ba7cf4de06143b2e5c8769385bfc60c11f07d
5
5
  SHA512:
6
- metadata.gz: a8c9cab594bacc8b84a46a69be08c77becd15fc9011de37e796a37e826ccbed3eb6b69e55a3ef078be64d1246a0f15ffe600711c67811cdb91f59480f8d46d2c
7
- data.tar.gz: fd7f450405a6ecbbed3a853bf9f794265bd4f8f19d9cfe3e015fd914a7f5d9620e1f72e7d839b349115683a8b0ffd89fd4d357c3cbdf3236ae38ce728b084c15
6
+ metadata.gz: 14d481c6476ac19d2f93cbe8f4ff49c6452f3e7060b04d41d21c72b59054850e03d1ec3e7419593d6b1d8d4ab117fd88916a97476e776f0c3bb478d92ddc6734
7
+ data.tar.gz: '096decdc1f6f6cb06c091f80f7fcf4679963dab96b4d28e5ef1fd62b02929bbf9b255e0c58fa961f7daf32130c113387bba54991a4584556cda5d6d7027aec00'
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
4
+ abort 'Please run annotate from the root of the project.'
5
+ end
6
+
7
+ require_relative '../lib/bamboo_legals'
8
+
9
+ get_type = ARGV[0] || "monolingual"
10
+ run_generator(get_type)
@@ -0,0 +1,36 @@
1
+ require 'fileutils'
2
+
3
+ require_relative 'generators/migration'
4
+ require_relative 'generators/model'
5
+ require_relative 'generators/controller'
6
+ require_relative 'generators/views'
7
+ require_relative 'generators/routes'
8
+ require_relative 'generators/manual'
9
+
10
+ def run_generator(get_type)
11
+ if get_type == "monolingual" or get_type == "mono"
12
+ type = "monolingual"
13
+
14
+ `rails g model Legal title:string content:text is_visible:boolean position:integer`
15
+ elsif get_type == "multilingual" or get_type == "multi"
16
+ type = "multilingual"
17
+
18
+ `rails g model Legal is_visible:boolean position:integer`
19
+ `rails g model LegalTranslation title:string content:text language_id:string position:integer legal_id:integer`
20
+ end
21
+
22
+ if type
23
+ overwrite_migration
24
+ overwrite_model(type)
25
+
26
+ create_admin_controller(type)
27
+ create_controller(type)
28
+ create_admin_views(type)
29
+ create_views(type)
30
+
31
+ overwrite_routes
32
+ print_manual(type)
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,21 @@
1
+ def create_admin_controller(type)
2
+ # find the legal controller
3
+ controller_path = "app/controllers/admin/legals_controller.rb"
4
+ template_controller_path = "bamboo_legals/lib/templates/#{type}/admin_legals_controller.txt"
5
+
6
+ new_controller_text = File.open(template_controller_path).read
7
+ File.write(controller_path, new_controller_text)
8
+
9
+ puts "++ Created -> #{controller_path}"
10
+ end
11
+
12
+ def create_controller(type)
13
+ # find the legal controller
14
+ controller_path = "app/controllers/legals_controller.rb"
15
+ template_controller_path = "bamboo_legals/lib/templates/#{type}/legals_controller.txt"
16
+
17
+ new_controller_text = File.open(template_controller_path).read
18
+ File.write(controller_path, new_controller_text)
19
+
20
+ puts "++ Created -> #{controller_path}"
21
+ end
@@ -0,0 +1,47 @@
1
+ def print_manual(type)
2
+ puts ""
3
+ puts "++ Add locales"
4
+ puts """
5
+ admin_nav:
6
+ legals: \"Legal Pages\"
7
+
8
+ activerecord:
9
+ attributes:
10
+ legal:
11
+ is_visible: \"Page is visible?\"
12
+ title: \"Title\"
13
+ content: \"Content\"
14
+ created_at: \"Created at\"
15
+ errors:
16
+ models:
17
+ legal:
18
+ attributes:
19
+ title:
20
+ blank: \"Title can't be blank!\"
21
+ content:
22
+ blank: \"Content can't be blank!\"
23
+ """
24
+ puts ""
25
+ puts "++ Add to app/views/layouts/admin/_navigation.html.erb"
26
+ puts """
27
+ <% if current_admin.permitted?(:legals) %>
28
+ <%= active_link_to admin_legals_path, class: 'sidebar__link', active: :inclusive, class_active: 'active-link' do %>
29
+ <%= inline_svg \"icons/nav/court.svg\", class: 'sidebar__icon', width: 16, height: 16 %>
30
+ <%= t(\"admin_nav.legals\") %>
31
+ <% end %>
32
+ <% end %>
33
+ """
34
+ if type == "multilingual"
35
+ puts ""
36
+ puts "++ Maybe you are missing some helpers..."
37
+ puts """
38
+ look here: https://gitlab.com/bamboolab/b4b/-/blob/master/app/helpers/admin/language_helper.rb
39
+ """
40
+ end
41
+
42
+ puts ""
43
+ puts "++ Run"
44
+ puts """
45
+ rake db:migrate
46
+ """
47
+ end
@@ -0,0 +1,21 @@
1
+ def overwrite_migration
2
+ # find the legal migration
3
+ migrations_path = "db/migrate/"
4
+ migration_path = "#{migrations_path}#{Dir.entries(migrations_path).grep(/_create_legals.rb$/).first}"
5
+
6
+ new_migration_text = ""
7
+ migration = File.open(migration_path).read
8
+ migration.each_line do |line|
9
+ # add detault: true to migration
10
+ if line.include?("t.boolean :is_visible")
11
+ new_migration_text += " t.boolean :is_visible, default: true \n"
12
+ else
13
+ new_migration_text += line
14
+ end
15
+ end
16
+
17
+ # rewrite the migration file
18
+ File.write(migration_path, new_migration_text)
19
+
20
+ puts "++ Changed -> #{migration_path}"
21
+ end
@@ -0,0 +1,20 @@
1
+ def overwrite_model(type)
2
+ # find the legal model
3
+ model_path = "app/models/legal.rb"
4
+ template_model_path = "bamboo_legals/lib/templates/#{type}/legal.txt"
5
+
6
+ new_model_text = File.open(template_model_path).read
7
+ File.write(model_path, new_model_text)
8
+
9
+ puts "++ Changed -> #{model_path}"
10
+
11
+ if type == "multilingual"
12
+ model_translation_path = "app/models/legal_translation.rb"
13
+ template_model_translation_path = "bamboo_legals/lib/templates/#{type}/legal_translation.txt"
14
+
15
+ new_model_translation_text = File.open(template_model_translation_path).read
16
+ File.write(model_translation_path, new_model_translation_text)
17
+
18
+ puts "++ Changed -> #{model_translation_path}"
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ def overwrite_routes
2
+ # find the routes
3
+ route_path = "config/routes.rb"
4
+
5
+ # text that will overwrite namespace :admin do
6
+ to_add = """ resources :legals, only: [:show]
7
+ namespace :admin do
8
+ resources :legals, except: [:show] do
9
+ collection { patch :sort }
10
+ end
11
+ """
12
+
13
+ new_routes_text = ""
14
+ routes = File.open(route_path).read
15
+ routes.each_line do |line|
16
+ # add routes for legal
17
+ if line.include?("namespace :admin do")
18
+ new_routes_text += to_add
19
+ else
20
+ new_routes_text += line
21
+ end
22
+ end
23
+
24
+ # rewrite the routes file
25
+ File.write(route_path, new_routes_text)
26
+
27
+ puts "++ Changed -> #{route_path}"
28
+ end
@@ -0,0 +1,37 @@
1
+ def create_admin_views(type)
2
+ admin_view_dir_path = 'app/views/admin/legals/'
3
+
4
+ # create directory for legal views in admin
5
+ Dir.mkdir admin_view_dir_path
6
+
7
+ # find all template views
8
+ template_views_path = "bamboo_legals/lib/templates/#{type}/admin_views/"
9
+ Dir.entries(template_views_path).each do |template|
10
+ next if template == "." or template == ".."
11
+
12
+ new_text = File.open("#{template_views_path}#{template}").read
13
+ new_file_name = "#{admin_view_dir_path}#{template.split(".")[0]}.html.erb"
14
+ File.write(new_file_name, new_text)
15
+
16
+ puts "++ Created -> #{new_file_name}"
17
+ end
18
+ end
19
+
20
+ def create_views(type)
21
+ view_dir_path = 'app/views/legals/'
22
+
23
+ # create directory for legal views
24
+ Dir.mkdir view_dir_path
25
+
26
+ # find all template views
27
+ template_views_path = "bamboo_legals/lib/templates/#{type}/views/"
28
+ Dir.entries(template_views_path).each do |template|
29
+ next if template == "." or template == ".."
30
+
31
+ new_text = File.open("#{template_views_path}#{template}").read
32
+ new_file_name = "#{view_dir_path}#{template.split(".")[0]}.html.erb"
33
+ File.write(new_file_name, new_text)
34
+
35
+ puts "++ Created -> #{new_file_name}"
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ class Admin::LegalsController < Admin::BaseController
2
+ before_action :set_legal, only: [:edit, :update, :destroy]
3
+
4
+ def index
5
+ @legals = Legal.all
6
+ end
7
+
8
+ def new
9
+ @legal = Legal.new
10
+ end
11
+
12
+ def edit
13
+ end
14
+
15
+ def create
16
+ @legal = Legal.new(legal_params)
17
+ if @legal.save
18
+ redirect_to admin_legals_path, notice: t('saved_successfully')
19
+ else
20
+ render :new
21
+ end
22
+ end
23
+
24
+ def update
25
+ if @legal.update(legal_params)
26
+ redirect_to admin_legals_path, notice: t('saved_successfully')
27
+ else
28
+ render :edit
29
+ end
30
+ end
31
+
32
+ def destroy
33
+ redirect_to admin_legals_path, alert: t('deleted_successfully')
34
+ end
35
+
36
+ def sort
37
+ params[:legal].each_with_index do |id, index|
38
+ Legal.where(id: id).update_all(position: index + 1)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def set_legal
45
+ @legal = Legal.find{ |t| t.title.parameterize == params[:id]}
46
+ end
47
+
48
+ def legal_params
49
+ params.require(:legal).permit(:title, :content, :is_visible)
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ <%= form_for [:admin, @legal], url: (@legal.new_record? ? admin_legals_path : admin_legal_path(id: @legal)), :html => {role: 'form', class: 'form'} do |f| %>
2
+ <fieldset class="form__fieldset">
3
+ <%=render partial: 'layouts/error_messages', as: :object, object: @legal %>
4
+ </fieldset>
5
+
6
+ <fieldset class="form__fieldset">
7
+ <div class="form__field">
8
+ <%= f.label :title, class: 'label' %>
9
+ <%= f.text_field :title, class: 'input' %>
10
+ </div>
11
+
12
+ <div class="form__field">
13
+ <%= f.label :content, class: 'label' %>
14
+ <%= f.text_area :content, class: 'input tinymce' %>
15
+ </div>
16
+
17
+ <div class="form__field input__field--text">
18
+ <%= f.check_box :is_visible, class: "input" %>
19
+ <%= f.label :is_visible, class: 'label' %>
20
+ </div>
21
+ </fieldset>
22
+ <fieldset class="form__fieldset">
23
+ <div class="field">
24
+ <%=f.submit t('save'), class: 'btn btn--full', data: {disable_with: '...'} %>
25
+ </div>
26
+ </fieldset>
27
+ <% end %>
28
+
29
+ <script>
30
+ $(document).ready(function(){
31
+ load_tiny();
32
+ });
33
+ </script>
@@ -0,0 +1,15 @@
1
+ <tr id=<%= dom_id(legal) %> class="table__item--wrap">
2
+ <td class="table__item col col--1"> <%#= image_tag("icons/dragndrop.png", height: '32', width: '32') %> </td>
3
+ <td class="table__item col col--1"><%= legal.title %></td>
4
+ <td class="table__item col col--1"><%= raw(legal.is_visible ? "&#10004;" : "&#10006;") %></td>
5
+ <td class="table__item col col--1" data-sort="<%= legal.created_at.strftime("%Y%m%d") %>"><%= legal.created_at.strftime("%d.%m.%Y.") %></td>
6
+ <td class="table__item table__icon--wrap col col--1">
7
+ <%= link_to edit_admin_legal_path(legal), class: "table__icon", "data-tooltip" => t('edit_tooltip') do %>
8
+ <%= inline_svg "icons/pen-group-3.svg" %>
9
+ <% end %>
10
+
11
+ <%= link_to [:admin, legal], method: :delete, data: { confirm: t('delete_confirm') }, class: "table__icon", "data-tooltip" => t('delete_tooltip') do %>
12
+ <%= inline_svg "icons/trash-simple.svg" %>
13
+ <% end %>
14
+ </td>
15
+ </tr>
@@ -0,0 +1,15 @@
1
+ <header class="header header--small">
2
+ <%= link_to admin_legals_path, class: "btn btn--back" do %>
3
+ <div class="arrow--left"></div>
4
+ <% end %>
5
+
6
+ <div class="header__content">
7
+ <h1><%= t('admin_nav.legals') %></h1>
8
+ <span class="main__subtitle"><%= t('edit') %></span>
9
+ </div>
10
+ </header>
11
+
12
+
13
+ <section class="section section--padded section--8">
14
+ <%= render 'form' %>
15
+ </section>
@@ -0,0 +1,31 @@
1
+ <header class="header header--double">
2
+ <h1><%= t('admin_nav.legal') %></h1>
3
+ <%= link_to t('create'), new_admin_legal_path, class: "btn btn--primary btn--large" %>
4
+ </header>
5
+
6
+ <section class="section section--12 section--double">
7
+
8
+ <table class="datatable table__icon--4">
9
+ <thead>
10
+ <tr class="table__head--wrap">
11
+ <td class="table__item col col--1"> </td>
12
+ <th class="table__head col col--1"><%= t('activerecord.attributes.legal.title') %></th>
13
+ <th class="table__head col col--1"><%= t('activerecord.attributes.legal.is_visible') %> </th>
14
+ <th class="table__head col col--1"><%= t('activerecord.attributes.legal.created_at') %> </th>
15
+ <th class="table__head col col--1"><%= t('actions') %></th>
16
+ </tr>
17
+ </thead>
18
+
19
+ <tbody class="sortable" data-url='<%=sort_admin_legals_path %>' >
20
+ <% @legals.each do |legal| %>
21
+ <%= render "legal", legal: legal %>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+ </section>
26
+
27
+ <script>
28
+ $(function(){
29
+ // init_datatable("<%= I18n.locale %>");
30
+ })
31
+ </script>
@@ -0,0 +1,15 @@
1
+ <header class="header header--small">
2
+ <%= link_to admin_legals_path, class: "btn btn--back" do %>
3
+ <div class="arrow--left"></div>
4
+ <% end %>
5
+
6
+ <div class="header__content">
7
+ <h1><%= t('admin_nav.legals') %></h1>
8
+ <span class="main__subtitle"><%= t('new') %></span>
9
+ </div>
10
+ </header>
11
+
12
+
13
+ <section class="section section--padded section--8">
14
+ <%= render 'form' %>
15
+ </section>
@@ -0,0 +1,26 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: legals
4
+ #
5
+ # id :bigint not null, primary key
6
+ # title :string
7
+ # content :text
8
+ # position :integer
9
+ # is_visible :boolean default("true")
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
12
+ #
13
+ class Legal < ApplicationRecord
14
+ include LogActions
15
+ default_scope { order(:position) }
16
+ validates_presence_of :title, :content
17
+
18
+ def self.all_visible
19
+ where(is_visible: true)
20
+ end
21
+
22
+ def to_param
23
+ "#{self.title.parameterize}"
24
+ end
25
+
26
+ end
@@ -0,0 +1,5 @@
1
+ class LegalsController < ApplicationController
2
+ def show
3
+ @legal = Legal.find{ |t| t.title.parameterize == params[:id]}
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ <% unless @legals.blank? %>
2
+ <nav class="nav--footer nav--legal">
3
+ <% @legals.each do |legal| %>
4
+ <%= link_to legal.title, legal_path(legal), class: 'nav__link' %>
5
+ <% end %>
6
+ </nav>
7
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <!-- SEO -->
2
+ <% content_for :title, "#{@legal.title}" %>
3
+ <% content_for :description, truncate(strip_tags(@legal.content), length: 160 ) %>
4
+
5
+ <div class="layout--main">
6
+ <div class="section">
7
+ <h1><%= @legal.title %></h1>
8
+ </div>
9
+ <article class="article">
10
+ <%= raw @legal.content %>
11
+ </article>
12
+ </div>
@@ -0,0 +1,56 @@
1
+ class Admin::LegalsController < Admin::BaseController
2
+ before_action :set_legal, only: [:show, :edit, :update, :destroy]
3
+
4
+ def index
5
+ @legals = Legal.all
6
+ end
7
+
8
+ def new
9
+ @legal = Legal.new
10
+ end
11
+
12
+ def create
13
+ @legal = Legal.new(legal_params)
14
+
15
+ if @legal.save
16
+ redirect_to admin_legals_path, notice: t('saved_successfully')
17
+ else
18
+ render :new
19
+ end
20
+ end
21
+
22
+ def edit
23
+ end
24
+
25
+ def update
26
+ if @legal.update(legal_params)
27
+ redirect_to admin_legals_path, notice: t('saved_successfully')
28
+ else
29
+ render :edit
30
+ end
31
+ end
32
+
33
+ def destroy
34
+ if @legal.destroy
35
+ redirect_to admin_legals_path, notice: t('deleted')
36
+ else
37
+ redirect_to admin_legals_path, alert: t('not_deleted')
38
+ end
39
+ end
40
+
41
+ def sort
42
+ params[:legal].each_with_index do |id, index|
43
+ Legal.where(id: id).update_all(position: index + 1)
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def set_legal
50
+ @legal = LegalTranslation.find{|t| t.title.parameterize == params[:id]}.legal
51
+ end
52
+
53
+ def legal_params
54
+ params.require(:legal).permit(:is_visible, legal_translations_attributes: [:id, :title, :content, :language_id, :position, :keywords])
55
+ end
56
+ end
@@ -0,0 +1,43 @@
1
+ <%= form_for [:admin, @legal], url: (@legal.new_record? ? admin_legals_path : admin_legal_path(id: @legal)), :html => {role: 'form', class: 'form'} do |f| %>
2
+ <fieldset class="form__fieldset">
3
+ <%=render partial: 'layouts/error_messages', as: :object, object: @legal %>
4
+ </fieldset>
5
+
6
+ <fieldset class="form__fieldset">
7
+ <div class="form__field">
8
+ <%= f.fields_for :legal_translations do |ff| %>
9
+ <%= language_title(ff) %>
10
+
11
+ <div class="form__field">
12
+ <%= ff.label :title, class: 'label' %>
13
+ <%= ff.text_field :title, class: 'input' %>
14
+ </div>
15
+
16
+ <div class="form__field">
17
+ <%= ff.label :content, class: 'label' %>
18
+ <%= ff.text_area :content, class: 'input tinymce' %>
19
+ </div>
20
+
21
+ <%= ff.hidden_field :language_id, value: language_value(ff) %>
22
+ <%= ff.hidden_field :position, value: ff.options[:child_index] %>
23
+ <% end %>
24
+
25
+ <div class="form__field input__field--text">
26
+ <%= f.label :is_visible, class: 'label' %>
27
+ <%= f.check_box :is_visible, class: 'input' %>
28
+ </div>
29
+
30
+ </fieldset>
31
+
32
+ <fieldset class="form__fieldset">
33
+ <div class="field">
34
+ <%=f.submit t('save'), class: 'btn btn--full', data: {disable_with: '...'} %>
35
+ </div>
36
+ </fieldset>
37
+ <% end %>
38
+
39
+ <script>
40
+ $(document).ready(function(){
41
+ load_tiny("hr");
42
+ });
43
+ </script>
@@ -0,0 +1,13 @@
1
+ <header class="header header--small">
2
+ <%= link_to admin_legals_path, class: "btn btn--back" do %>
3
+ <div class="arrow--left"></div>
4
+ <% end %>
5
+
6
+ <div class="header__content">
7
+ <h1><%= t('admin_nav.legals') %></h1>
8
+ </div>
9
+ </header>
10
+
11
+ <div class="section section--padded section__wrap--8 js_part">
12
+ <%= render 'form' %>
13
+ </div>
@@ -0,0 +1,43 @@
1
+ <header class="header header--double">
2
+ <h1><%= t('admin_nav.legals') %></h1>
3
+ <%= link_to t('create'), new_admin_legal_path, class: "btn btn--primary btn--large" %>
4
+ </header>
5
+
6
+ <section class="section section--12 section--double">
7
+
8
+ <table class="datatable custom-table table__icon--4">
9
+ <thead>
10
+ <tr class="table__head--wrap">
11
+ <th class="table__head col col--1"> <%= t('drag_and_drop') %> </th>
12
+ <th class="table__head col col--1"><%= t('activerecord.attributes.legal_translation.title') %></th>
13
+ <th class="table__head col col--1"><%= t('activerecord.attributes.legal.created_at') %> </th>
14
+ <th class="table__head col col--1"><%= t('actions') %></th>
15
+ </tr>
16
+ </thead>
17
+
18
+ <tbody class="sortable" data-url='<%=sort_admin_legals_path %>' >
19
+ <% @legals.each do |legal| %>
20
+ <tr id=<%= dom_id(legal) %> class="table__item--wrap">
21
+ <td class="table__item col col--1"> <%#= image_tag("icons/dragndrop.png", height: '32', width: '32') %> </td>
22
+ <td class="table__item col col--1"><%= legal.translate.title %></td>
23
+ <td class="table__item col col--1" data-sort="<%= legal.created_at.strftime("%Y%m%d") %>"><%= legal.created_at.strftime("%d.%m.%Y.") %></td>
24
+ <td class="table__item table__icon--wrap col col--1">
25
+ <%= link_to edit_admin_legal_path(legal), class: "table__icon" do %>
26
+ <%= inline_svg "icons/pen-group-3.svg" %>
27
+ <% end %>
28
+
29
+ <%= link_to [:admin, legal], method: :delete, data: { confirm: t('delete_confirm') }, class: "table__icon" do %>
30
+ <%= inline_svg "icons/trash-simple.svg" %>
31
+ <% end %>
32
+ </td>
33
+ </tr>
34
+ <% end %>
35
+ </tbody>
36
+ </table>
37
+ </section>
38
+
39
+ <script>
40
+ $(function(){
41
+ // init_datatable("<%= I18n.locale %>");
42
+ })
43
+ </script>
@@ -0,0 +1,13 @@
1
+ <header class="header header--small">
2
+ <%= link_to admin_legals_path, class: "btn btn--back" do %>
3
+ <div class="arrow--left"></div>
4
+ <% end %>
5
+
6
+ <div class="header__content">
7
+ <h1><%= t('admin_nav.legals') %></h1>
8
+ </div>
9
+ </header>
10
+
11
+ <div class="section section--padded section__wrap--8 js_part">
12
+ <%= render 'form' %>
13
+ </div>
@@ -0,0 +1,32 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: legals
4
+ #
5
+ # id :bigint not null, primary key
6
+ # position :integer
7
+ # is_visible :boolean default("true")
8
+ # created_at :datetime not null
9
+ # updated_at :datetime not null
10
+ #
11
+ class Legal < ApplicationRecord
12
+ include LogActions
13
+
14
+ has_many :legal_translations, dependent: :destroy
15
+ accepts_nested_attributes_for :legal_translations
16
+
17
+ include TranslationsInitializer
18
+ def to_param
19
+ "#{self.legal_translations.find_by(language_id: I18n.locale).title.parameterize}"
20
+ end
21
+
22
+ def translate(language_id=I18n.locale.to_s)
23
+ # commented code can be to added to app/models/concerns/translation_initializer.rb
24
+ # so other models can use it
25
+ #def translate(language_id=I18n.locale.to_s)
26
+ # translations = eval("#{self.model_name.param_key}_translations")
27
+ # translations.find_by(language_id: language_id)
28
+ #end
29
+
30
+ legal_translations.find_by(language_id: language_id)
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: legal_translations
4
+ #
5
+ # id :bigint not null, primary key
6
+ # title :string
7
+ # content :text
8
+ # legal_id :integer
9
+ # language_id :string
10
+ # position :integer
11
+ # keywords :string
12
+ # created_at :datetime not null
13
+ # updated_at :datetime not null
14
+ #
15
+ class LegalTranslation < ApplicationRecord
16
+ belongs_to :legal
17
+ default_scope { order(:position) }
18
+ end
@@ -0,0 +1,5 @@
1
+ class LegalsController < ApplicationController
2
+ def show
3
+ @legal = LegalTranslation.find{|t| t.title.parameterize == params[:id]}.legal
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ <h5><%= t('help') %></h5>
2
+ <ul class="footer__list">
3
+ <% @legals.each do |legal| %>
4
+ <li> <%= link_to legal.translate.title, legal_path(legal) %>
5
+ <% end %>
6
+ </ul>
@@ -0,0 +1,17 @@
1
+ <!-- SEO -->
2
+ <% content_for :title, "#{@legal.translate.title}" %>
3
+ <% content_for :description, truncate(strip_tags(@legal.translate.content), length: 160 ) %>
4
+
5
+ <div class="layout--full">
6
+ <div class="layout--main">
7
+ <div class="text--center">
8
+
9
+ <h2><%= @legal.translate.title %></h2>
10
+
11
+ <div class="post__text">
12
+ <%= raw @legal.translate.content %>
13
+ </div>
14
+
15
+ </div>
16
+ </div>
17
+ </div>
metadata CHANGED
@@ -1,23 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bamboo_legals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mislav Kvesić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-10 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: It should generate monolingual and multilingual legals for big_bamboom
14
14
  email: kvesic.mislav@gmail.com
15
15
  executables:
16
- - add_bamboo_legals
16
+ - bamboo_legals
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - bin/add_bamboo_legals
20
+ - bin/bamboo_legals
21
+ - lib/bamboo_legals.rb
22
+ - lib/generators/controller.rb
23
+ - lib/generators/manual.rb
24
+ - lib/generators/migration.rb
25
+ - lib/generators/model.rb
26
+ - lib/generators/routes.rb
27
+ - lib/generators/views.rb
28
+ - lib/templates/monolingual/admin_legals_controller.txt
29
+ - lib/templates/monolingual/admin_views/_form.txt
30
+ - lib/templates/monolingual/admin_views/_legal.txt
31
+ - lib/templates/monolingual/admin_views/edit.txt
32
+ - lib/templates/monolingual/admin_views/index.txt
33
+ - lib/templates/monolingual/admin_views/new.txt
34
+ - lib/templates/monolingual/legal.txt
35
+ - lib/templates/monolingual/legals_controller.txt
36
+ - lib/templates/monolingual/views/_index.txt
37
+ - lib/templates/monolingual/views/show.txt
38
+ - lib/templates/multilingual/admin_legals_controller.txt
39
+ - lib/templates/multilingual/admin_views/_form.txt
40
+ - lib/templates/multilingual/admin_views/edit.txt
41
+ - lib/templates/multilingual/admin_views/index.txt
42
+ - lib/templates/multilingual/admin_views/new.txt
43
+ - lib/templates/multilingual/legal.txt
44
+ - lib/templates/multilingual/legal_translation.txt
45
+ - lib/templates/multilingual/legals_controller.txt
46
+ - lib/templates/multilingual/views/_footer_legal.txt
47
+ - lib/templates/multilingual/views/show.html.txt
21
48
  homepage: https://rubygems.org/gems/bamboo_legals
22
49
  licenses:
23
50
  - MIT
@@ -25,7 +52,7 @@ metadata: {}
25
52
  post_install_message:
26
53
  rdoc_options: []
27
54
  require_paths:
28
- - bamboo_legals_lib
55
+ - lib
29
56
  required_ruby_version: !ruby/object:Gem::Requirement
30
57
  requirements:
31
58
  - - ">="
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
4
- abort 'Please run annotate from the root of the project.'
5
- end
6
-
7
- require 'rubygems'
8
- begin
9
- require 'bundler'
10
- Bundler.setup
11
- rescue StandardError
12
- end
13
-
14
- here = File.expand_path(File.dirname __FILE__)
15
- $LOAD_PATH << "#{here}/../bamboo_legals_lib"
16
-
17
- require_relative '../bamboo_legals_lib/bamboo_legals'
18
-
19
- get_type = ARGV[0] || "monolingual"
20
- run_generator(get_type)