Skip to content

Instantly share code, notes, and snippets.

Avatar

Owen Peredo Diaz owen2345

View GitHub Profile
@owen2345
owen2345 / sqlite3-to-mysql.rb
Last active Dec 15, 2016
Camaleon CMS migrate sqlite3 to mysql DB
View sqlite3-to-mysql.rb
#Take it line by line
pending_line = []
query_end = ');' # take care with insert content's ending with ");"
ARGF.each do |line|
# fix for: mapping values are not allowed in this context at (content used by rails for serialized model attributes)
if line.start_with?('INSERT INTO') && !line.strip.end_with?(query_end)
pending_line = [line.gsub("\n", '')]
next
end
if pending_line.length > 0 && !line.strip.end_with?(query_end)
@owen2345
owen2345 / settings.html.erb
Created Nov 11, 2016
Sample Theme Settings
View settings.html.erb
<!-- /my_theme/views/admin/settings.html.erb -->
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= t('.top_offer', default: 'Top Offer') %></h3>
</div>
<div class="panel-body">
<div class="form-group">
<label><%= t('.top_offer_product', default: 'Offer Product') %></label><br>
<%= select_tag "theme_option[top_offer]", options_from_collection_for_select(post_type.posts.public_posts.decorate, :id, :the_title, current_theme.get_option('top_offer')), include_blank: true, class: 'form-control' %>
</div>
@owen2345
owen2345 / paper_trail.rb
Last active Sep 7, 2016
(PaperTrail Extension) If you just want a summary of changes for a particular attribute of a model, you can use the history_from_audits_for method
View paper_trail.rb
# config/initializers/paper_trail.rb
PaperTrail::Model.module_eval do
# return an array of changes for specific attribute (old to newer)
# Sample use: Subscriber.find(2).history_from_audits_for(:first_name)
# Sample result: [{version: <PaperTrail::Version>, model: <Subscriber>}, {version: <PaperTrail::Version>, model: <MyModel>},....]
# Sample print: Subscriber.find(2).history_from_audits_for(:first_name).map{|item| item[:model].first_name }
# Required: Diffing Versions of paper trail
def history_from_audits_for(attr_name)
res = []
self.versions.each do |v|
@owen2345
owen2345 / Gemfile
Last active Nov 13, 2016
Camaleon CMS Create Own Custom Fields (Simple Country Select)
View Gemfile
#/themes/e_shop/config/Gemfile
gem 'country_select'
@owen2345
owen2345 / _myslider.html.erb
Last active Mar 13, 2020
Camaleon CMS Create Own Custom Fields (Complex)
View _myslider.html.erb
#/themes/e_shop/views/custom_field/_my_slider.html.erb
<div class="group-input-fields-content" data-callback-render="render_my_custom_slider">
<div class="form-group">
<label>Image:</label>
<div class="input-group">
<input data-dimension="<%= field.options[:dimension] %>" data-versions="<%= field.options[:versions] %>" data-thumb_size="<%= field.options[:thumb_size] %>" type="url" name="<%= field_name %>[<%= field.slug %>][values][][image]" class="data-error-place-parent image_field form-control <%= "required" if field.options[:required].to_s.to_bool %>"/>
<span class="input-group-addon btn_upload" onclick="load_upload_image_field($(this).prev());"><i class="fa fa-upload"></i> <%= t('camaleon_cms.admin.button.upload_image')%> <%= "(#{field.get_option('dimension')})" if field.get_option('dimension').present? %></span>
</div>
</div>
<div class="clearfix">
@owen2345
owen2345 / main_helper.rb
Created Jun 15, 2016
Perspective Theme (one click install). Template url: https://p.w3layouts.com/demos/perspective/web/index.html
View main_helper.rb
module Themes::PerspectiveTheme::MainHelper
def self.included(klass)
klass.helper_method [:perspective_social_networks] rescue "" # here your methods accessible from views
end
def perspective_theme_settings(theme)
# callback to save custom values of fields added in my_theme/views/admin/settings.html.erb
end
# callback called after theme installed
@owen2345
owen2345 / Adding posts in Camaleon CMS.rb
Created Jun 10, 2016
Sample how to add posts by code in Camaleon CMS
View Adding posts in Camaleon CMS.rb
pt_layout = current_site.post_types.where(slug: "camaleon_layout").first || current_site.post_types.create(name: "Layout", slug: "camaleon_layout", data_options: {has_summary: false, has_picture: false })
pt_layout.add_field({name: "Sub title", slug: "sub_title"}, {field_key: "text_box", translate: true})
pt_layout.add_field({name: "Background Image", slug: "bg", description: "Size (1900px x 900px)."}, {field_key: "image"})
pt_layout.add_field({name: "Background color", slug: "bg_color", description: ""}, {field_key: "colorpicker", color_format: "rgba"})
pt_layout.add_field({name: "Pattern", slug: "pattern", description: "Permit to show square pattern as a background."}, {field_key: "checkbox"})
ids << pt_layout.id
pt_layout.add_post(title: "Home Slider", post_order: 1, content: "Here will be shown the home slider", settings: {has_keywords: false, skip_fields: ["sub_title", "pattern", "bg", "bg_color"], default_template: "home/banner"})
pt_layout.add_post(title: "Features", post_order: 2, con
@owen2345
owen2345 / post.html.erb
Created Feb 10, 2016
Camaleon CMS Custom Fields
View post.html.erb
<h1><%= @post.the_title %></h1>
<div>
<%= raw @post.the_content %>
</div>
<hr>
<h2>Custom fields here:</h2>
<div>
Author name: <%= @post.get_field('author-name') %>
</div>
@owen2345
owen2345 / style
Last active Aug 29, 2015
less and sass code snippet
View style
/* ------------------ fonts -------------------*/
@font-face {
font-family: 'Union-Regular';
src: url('../font/unionregular.eot');
src: url('../font/unionregular.eot?#iefix') format('embedded-opentype'),
url('../font/unionregular.woff') format('woff'),
url('../font/unionregular.ttf') format('truetype'),
url('../font/unionregular.svg#unionregular') format('svg');
font-weight: normal;
font-style: normal;
View active directory connection
require 'net-ldap'
class CustomActiveDirectory
def initialize(host, port, base, username, pass)
@ldap = connect(host, port, base, username, pass)
end
def connected?
begin
return @ldap.bind
rescue