Last active
June 9, 2017 07:27
-
-
Save criess/b3590a49f5e2da75c5faed58c8d67bd9 to your computer and use it in GitHub Desktop.
workspace: webseite-rails3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateOverrideRedirectGroup < ActiveRecord::Migration | |
GROUP_NAME = "Redirect Override" | |
PERMISSION_NAME = "Redirect Override" | |
PERMISSION_KEY = "redirect_override" | |
PERMISSION_DESC = "Disable Redirects for Cms Users" | |
def up | |
# create group | |
group = Cms::Group.new :name => GROUP_NAME, :group_type => Cms::GroupType.where("cms_access = true").first | |
group.save | |
# create permission | |
perm = Cms::Permission.new :name => "#{PERMISSION_KEY}", :full_name => "#{PERMISSION_NAME}", :description => "#{PERMISSION_DESC}" | |
perm.save | |
# add permission to group | |
group.permissions = Array.wrap perm | |
group.save | |
end | |
def down | |
# delete group | |
Cms::Group.where(:name => "#{GROUP_NAME}").each do |c| c.delete end | |
# delete permission | |
Cms::Permission.where(:name => "#{PERMISSION_KEY}").each do |c| c.delete end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def user_id | |
@user_id ||= Cms::User.find_by_login("christoph").id | |
end | |
def pages | |
p_ids = Cms::Section.where("name" => "Glossar").map(&:pages).flatten.map(&:id) | |
@pages ||= Cms::Page.where("id IN (?)", p_ids).where(*path_filter) | |
end | |
def o_glossar_trustgrey_block | |
name = "Organism: OGlossarTrustgrey" | |
@block_tg ||= Cms::HtmlBlock.where(:name => name).first_or_initialize | |
if @block_tg.new_record? | |
@block_tg.content = | |
<<-TOPME | |
<!-- OGlossarTrustgrey --> | |
<div class="o-glossar o-glossar-trustgrey none block-t"> | |
<div class="box"> | |
<p class="a-text a-text-paragraphalt"> | |
kautionsfrei.de ist bekannt aus | |
</p> | |
<ul class="m-list m-list-presslogos"> | |
<li class="a-listitem a-listitem-presslogo"> | |
<img class="a-image a-image-static" srcset="/assets/logos/press_guter_rat.png" alt="Logo der Pressereferenz Guter Rat"></li> | |
<li class="a-listitem a-listitem-presslogo"> | |
<img class="a-image a-image-static" srcset="/assets/logos/press_closer.png" alt="Logo der Pressereferenz Closer"></li> | |
<li class="a-listitem a-listitem-presslogo"> | |
<img class="a-image a-image-static" srcset="/assets/logos/press_frankfurter.png" alt="Logo der Pressereferenz Frankfurter Allgemeine"></li> | |
<li class="a-listitem a-listitem-presslogo"> | |
<img class="a-image a-image-static" srcset="/assets/logos/press_berliner_zeitung.png" alt="Logo der Pressereferenz Berliner Zeitung"></li> | |
<li class="a-listitem a-listitem-presslogo"> | |
<img class="a-image a-image-static" srcset="/assets/logos/press_handelsblatt.png" alt="Logo der Pressereferenz Handelsblatt"></li> | |
<li class="a-listitem a-listitem-presslogo"> | |
<img class="a-image a-image-static" srcset="/assets/logos/press_passauer.png" alt="Logo der Pressereferenz Passauer"></li> | |
</ul> | |
</div> | |
</div> | |
TOPME | |
@block_tg.created_by_id = user_id | |
@block_tg.updated_by_id = user_id | |
@block_tg.save | |
@block_tg.publish | |
@block_tg.reload | |
end | |
@block_tg | |
end | |
def o_glossar_ask_block | |
name = "Organism: OGlossarAsk" | |
@block_as ||= Cms::HtmlBlock.where(:name => name).first_or_initialize | |
if @block_as.new_record? | |
@block_as.content = | |
<<-TOPME | |
<!-- OGlossarAsk --> | |
<div class="o-glossar o-glossar-ask"> | |
<div class="box"> | |
<h1 class="a-headline a-headline-section-black casesensitive"> | |
Fragen Sie uns!</h1> | |
<p class="a-text a-text-parapgraphalt"> | |
Wir helfen Ihnen gerne weiter. … oder über unsere <a class="a-link a-link-underline" href="/haeufige-fragen">FAQ</a> | |
</p> | |
<div class="row"> | |
<div class="o-glossar-ask-box"> | |
<!-- MBoxContact --> | |
<div class="m-box m-box-contact a-border-layered-white"> | |
<div class="m-box-contact-left"> | |
<img alt="Illustration für die Kontaktart Chat" class="a-image a-image-static" srcset="/icons/icon_chat.png"></div> | |
<div class="m-box-contact-right"> | |
<h5 class="a-headline a-headline-box"> | |
Chat Mo-Fr 8-18 Uhr</h5> | |
<p class="a-text a-text-parapgraphalt"> | |
Chatten Sie jetzt mit unseren Beratern, um Ihre Fragen beantwortet zu bekommen.</p> | |
</div> | |
<a class="a-button a-button-fill green casesensitive" href="#">Chat starten</a> | |
</div> | |
</div> | |
<div class="o-glossar-ask-box"> | |
<!-- MBoxContact --> | |
<div class="m-box m-box-contact a-border-layered-white"> | |
<div class="m-box-contact-left"> | |
<a href="tel:+498000122333"> | |
<img alt="Illustration für die Kontaktart Hotline" class="a-image a-image-static" srcset="/icons/icon_phone.png"> | |
</a> | |
</div> | |
<div class="m-box-contact-right"> | |
<h5 class="a-headline a-headline-box"> | |
Kostenlose Hotline 24h</h5> | |
<p class="a-text a-text-parapgraphalt"> | |
Rufen Sie uns kostenlos an und werden Sie Ihre Fragen los. Unsere Berater helfen weiter.</p> | |
</div> | |
<a class="a-button a-button-fill green casesensitive" href="tel:+498000122333">0800 - 01 22 333</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
TOPME | |
@block_as.created_by_id = user_id | |
@block_as.updated_by_id = user_id | |
@block_as.save | |
@block_as.publish | |
@block_as.reload | |
end | |
@block_as | |
end | |
def o_glossar_topic_block | |
name = "Organism: OGlossarTopic" | |
@block_tl ||= Cms::HtmlBlock.where(:name => name).first_or_initialize | |
if @block_tl.new_record? | |
@block_tl.content = | |
<<-TOPME | |
<!-- OGlossarTopic --> | |
<div class="o-glossar o-glossar-topic"> | |
<div class="box"> | |
<h3 class="a-headline a-headline-section-black casesensitive"> | |
Weitere Themen?</h3> | |
<p class="a-text a-text-parapgraphalt"> | |
Lorem ipsum dolorem mal Zuwinka <a class="a-link a-link-underline" href="/mit-link-a-underline">Platzhalter-Link</a> | |
</p> | |
<div class="row"> | |
<div class="o-glossar-topic-box none block-t"> | |
<a href="/link-topic-1" title="Link Topic #1"> | |
<img alt="Illustration Topic #1" class="a-image a-image-static" srcset="https://placehold.it/800x480/91c002/ffffff?text=Topic%20%231"> | |
<a> | |
</div> | |
<div class="o-glossar-topic-box"> | |
<a href="/link-topic-2" title="Link Topic #2"> | |
<img alt="Illustration Topic #2" class="a-image a-image-static" srcset="https://placehold.it/800x480/749a00/ffffff?text=Topic%20%232"> | |
<a> | |
</div> | |
<div class="o-glossar-topic-box none block-t"> | |
<a href="/link-topic-3" title="Link Topic #3"> | |
<img alt="Illustration Topic #3" class="a-image a-image-static" srcset="https://placehold.it/800x480/91c002/ffffff?text=Topic%20%233"> | |
<a> | |
</div> | |
</div> | |
</div> | |
</div> | |
TOPME | |
@block_tl.created_by_id = user_id | |
@block_tl.updated_by_id = user_id | |
@block_tl.save | |
@block_tl.publish | |
@block_tl.reload | |
end | |
@block_tl | |
end | |
def js_integration_block | |
name = "Organism: OGlossarContentbox" | |
@block_react ||= Cms::HtmlBlock.where(:name => name).first_or_initialize | |
if @block_react.new_record? | |
@block_react.content = | |
<<-TOPME | |
<div id="OGlossarContentbox"></div> | |
<script type="text/javascript"> | |
(function() { | |
var tries = 0; | |
setTimeout( | |
function() { | |
if (typeof js_plusforta_com == "undefined") { | |
if ( tries < 10 ) { | |
tries = tries + 1; | |
setTimeout(arguments.callee, 500); | |
} | |
return; | |
} else { | |
if (typeof cms_edit_mode != "undefined" && cms_edit_mode) { | |
// abort js here! | |
return; | |
} | |
var contentInner = []; | |
var titlesToc = []; | |
var superHeadline = ""; | |
// find nodes an parse | |
for ( var n = 0; n < document.getElementsByClassName("m-glossar-info").length; n++ ) { | |
var node = document.getElementsByClassName("m-glossar-info")[n]; | |
if ( node.getElementsByTagName("h1").length > 0 ) { | |
var ref = node.getElementsByTagName("h1")[0]; | |
superHeadline = ref.innerHTML.replace(/<[^>]+>/g,""); | |
ref.parentNode.removeChild(ref); | |
} | |
titlesToc.push(node.children[0].innerHTML.replace(/<[^>]+>/g,"")); | |
contentInner.push(node.innerHTML); | |
node.setAttribute("style","display: none;"); | |
} | |
js_plusforta_com.ReactDOM.render( | |
js_plusforta_com.React.createElement( | |
js_plusforta_com.OGlossarContentbox, | |
{ | |
contentInner: contentInner, | |
titlesToc: titlesToc, | |
superHeadline: superHeadline, | |
ratingPrefix: "glossar-question-" | |
} | |
), | |
document.getElementById("OGlossarContentbox") | |
); | |
return; | |
} | |
}, 100); | |
})(); | |
</script> | |
TOPME | |
@block_react.created_by_id = user_id | |
@block_react.updated_by_id = user_id | |
@block_react.save | |
@block_react.publish | |
@block_react.reload | |
end | |
@block_react | |
end | |
def new_page(page) | |
ts = "t#{Time.now.to_i / 10}" | |
tmp_page = Cms::Page.new | |
tmp_page.path = File.join(page.section.path, "#{page.path}-#{ts}") | |
tmp_page.section = page.section | |
tmp_page.keywords = "class:p-landingpage-1" | |
tmp_page.name = "#{page.name} #{ts}" | |
tmp_page.created_by_id = user_id | |
tmp_page.updated_by_id = user_id | |
tmp_page.hidden = true | |
tmp_page.template_file_name = "full-head-foot.html.erb" | |
tmp_page.save | |
tmp_page.publish | |
tmp_page | |
end | |
def current_contents(page, regex_content_filter = /\A[^<]*<h2/m) | |
page.connectors.where(:page_version => page.version).map(&:connectable).map(&:content).select do |loop_content| | |
"#{loop_content}".match regex_content_filter | |
end.map do |loop_content| | |
# split at h2 headlines and regroup | |
ret = [] | |
loop_content.split(/(<h2)/).each do |part| | |
if part.match(/<h2/) | |
ret << "" | |
end | |
ret.last << part if ret.last | |
end | |
ret | |
end.flatten | |
end | |
def transform_connectors(page) | |
prepared = current_contents(page, /<h2/).inject({}) do |collect, block| | |
doc = Nokogiri::HTML.parse(block) | |
match = doc.xpath("(//p|//ul|//ol|//h2|//*[contains(@class, 'btn')])") | |
out = "<div class=\"m-glossar m-glossar-info box\">" | |
begin | |
name = "#{doc.xpath("//h2").first.text.strip}" | |
rescue | |
next collect | |
end | |
match.each do |output| | |
if output.node_name == "a" | |
out << "<a class=\"a-link a-link-underline\" href=\"#{output["href"]}\">#{output.text}</a>\n" | |
next | |
end | |
if output.node_name == "p" | |
output.children.each do |c| | |
c.node_name == "span" && | |
c.replace("#{c.text}") | |
end | |
output["class"] = "a-text a-text-paragraphalt" | |
end | |
if output.node_name == "ol" | |
output["class"] = "m-list m-list-numbers" | |
output.children.each do |c| | |
c["class"] = "a-listitem a-listitem-number" | |
end | |
end | |
if output.node_name == "ul" | |
output["class"] = "m-list m-list-advantages" | |
output.children.each do |c| | |
c["class"] = "glyphicons glyphicons-ok a-listitem a-listitem-advantage" | |
end | |
end | |
if output.node_name == "h2" | |
output["class"] = "a-headline-paragraphalt" | |
end | |
out << "#{output}\n" | |
end | |
begin | |
doc.xpath("//img").first.tap do |node| | |
next if node.nil? | |
img_source = node["src"] | |
str = | |
<<-OIC | |
<img class="a-image a-image-picture" srcset="#{img_source}" alt="Bild von #{File.basename(img_source)}"> | |
OIC | |
out << "#{str}" | |
end | |
rescue | |
$stdout << "Error (IMG Node)" << "\n" | |
$stdout << "#{block.gsub("\n","\n++ ")}" << "\n" | |
raise $! | |
end | |
out += "</div>" | |
collect[name] = out | |
collect | |
end | |
templ_container_key = :content | |
tmp_page = new_page(page) | |
raise "#{tmp_page.errors.messages}" unless tmp_page.errors.empty? | |
tmp_page.create_connector(js_integration_block, templ_container_key) | |
prepared.each_with_index do |(k,b), i| | |
# try to find superheadline (h1) | |
suffix = " - Fakten, Vorteile, Regeln, Vorlagen & Tipps" | |
if k.split(":").size > 1 && i == 0 | |
b = b.gsub( | |
"<div class=\"m-glossar m-glossar-info box\">", | |
"<div class=\"m-glossar m-glossar-info box\"><h1 class=\"a-headline a-headline-section-black\">#{k.split(":").first}#{suffix}</h1>\n" | |
) | |
end | |
block = Cms::HtmlBlock.new(:name => "MGlossarInfo " << k, :content => b).tap do |block| | |
block.created_by_id = user_id | |
block.updated_by_id = user_id | |
block.save | |
block.publish | |
end | |
tmp_page.create_connector(block, templ_container_key) | |
end | |
tmp_page.create_connector(o_glossar_topic_block, templ_container_key) | |
tmp_page.create_connector(o_glossar_ask_block, templ_container_key) | |
tmp_page.create_connector(o_glossar_trustgrey_block, templ_container_key) | |
# return newly created page | |
tmp_page.publish if publish_flag? | |
tmp_page | |
end | |
def publish_flag? | |
!ARGV.empty? && ARGV.include?("--publish") | |
end | |
def path_filter | |
if !ARGV.empty? && (opt = ARGV.find do |opt| | |
opt.match(/^--path=\/.*$/) | |
end) | |
["path = ?", "#{opt.split("=").last}"] | |
else | |
Array.wrap 1 | |
end | |
end | |
# deprecated | |
# method not used any more | |
def print_tree(node, level = 0, node_names = {}) | |
if level == 1 | |
if "#{node.node_name}" != "text" | |
node_names[node.node_name] ||= 0 | |
node_names[node.node_name] += 1 | |
end | |
end | |
if node.children | |
if "#{node.node_name}" != "text" | |
puts "#{" " * level} #{node.node_name}" | |
end | |
node.children.each do |n| | |
print_tree(n , level + 1, node_names) | |
end | |
else | |
if "#{node.node_name}" != "text" | |
puts "#{" " * level} #{node.node_name}" | |
end | |
end | |
node_names | |
end | |
# main | |
# all pages create transform_connectors | |
pages.each do |p| | |
transform_connectors(p) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'active_support/core_ext' | |
require 'google/apis/storage_v1' | |
require 'googleauth' | |
arg_key_file = ARGV.find do |entry| | |
entry.match /^--key-file=/ | |
end.try(:gsub, /^--key-file=/, "") | |
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = arg_key_file | |
scopes = [ | |
'https://www.googleapis.com/auth/devstorage.full_control' | |
] | |
authorization = Google::Auth.get_application_default(scopes) | |
api = Google::Apis::StorageV1::StorageService.new | |
api.authorization = authorization | |
project = "logical-cubist-220" | |
cdn_name_list = %w(cdn1-pfcom cdn2-pfcom cdn3-pfcom cdn4-pfcom cdn5-pfcom cdn6-pfcom) | |
cdn_name_list.each do |cdn_name| | |
unless api.list_buckets(project).items.map(&:name).include?(cdn_name) | |
bucket = Google::Apis::StorageV1::Bucket.new | |
bucket.name = cdn_name | |
bucket.location = "EU" | |
api.insert_bucket(project, bucket) | |
end | |
end | |
if (defined? Cms) && (defined? Cms::ImageBlock) | |
cdn_name = "cdn1-pfcom" #cdn_name_list.shuffle.first | |
Cms::ImageBlock.includes(:attachments).all.map(&:file).each do |file| | |
next unless File.exists? file.path | |
upload_source = file.path | |
object = Google::Apis::StorageV1::Object.new | |
object.name = file.data_file_path[1..2048] | |
object.content_disposition = "inline; filename=\"#{File.basename(object.name)}\"" | |
puts "Uploading <#{object.name}> from #{upload_source} onto #{cdn_name} ..." | |
object = api.insert_object( | |
cdn_name, | |
object, | |
:predefined_acl => "publicRead", | |
:upload_source => upload_source | |
) | |
object.content_type = `file -b --mime-type #{upload_source}`.strip | |
api.update_object( | |
cdn_name, | |
object.name, | |
object | |
) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'csv' | |
require 'optparse' | |
begin | |
GonePage | |
rescue | |
$stderr << "Cant access Database interface" << "\n" | |
exit 2 # ''2'' NO_DATABASE_FOUND_EXIT | |
end | |
file_ref = nil | |
parser = OptionParser.new do |options| | |
options.on '-l', '--loadfile FILE', 'Load csv import from FILE' do |arg| | |
file_ref = arg | |
end | |
end | |
parser.parse! | |
$stdout << "Process ... #{file_ref}" << "\n" | |
CSV.foreach("#{file_ref}","rb") do |row| | |
unless GonePage.find_by_url(row[0]) | |
GonePage.new.tap do |pref| | |
pref.url = row[0] | |
pref.save | |
end | |
end | |
end | |
$stdout << "Done ... #{file_ref}" << "\n" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment