Skip to content

Commit

Permalink
Added RakeFile and submodules script to handle fetching of resources …
Browse files Browse the repository at this point in the history
…from external repositories.
  • Loading branch information
Iankodj committed May 20, 2015
1 parent 73fa205 commit c04c1ef
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
30 changes: 30 additions & 0 deletions RakeFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
task :xaml_docs do
require "./helper_tools/submodules.rb"
submodule = Submodule.new("xaml_docs", "./helper_tools/submodules.yml")
submodule.init()
submodule.update()
submodule.map_folders()
submodule.destroy()

# replace all {% if site.site_name == 'WPF' %}
# to {% if site.site_name == 'AJAX' %}

original_regex = /{% if site.site_name == 'WPF' %}WPF|{% if site.site_name == 'WPF' %}/
original_string = "{% if site.site_name == 'WPF' %}"
replacement = "{% if site.site_name == 'AJAX' %}"

folders = submodule.get_target_folders()
folders.each do |folder|
files = Dir[folder + "**/*.md"]
files.each do |file|
content = File.read(file)
if content.include?(original_string)
#content = content.gsub(original, replacement)
content = content.gsub(original_regex){ |match|
match.end_with?("WPF") ? replacement + "AJAX" : replacement
}
File.write(file, content)
end
end
end
end
43 changes: 43 additions & 0 deletions helper_tools/submodules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "yaml"
require "fileutils"

class Submodule
def initialize(name, config_file)
@name = name
@config = YAML.load_file(config_file)[name]
end

def init
system "git submodule add -f #{@config['remote_ssh']} #{@config['submodule_path']}"
end

def update
system "git submodule update --remote -f #{@config['submodule_path']}"
end

def destroy
system "git submodule deinit -f #{@config['submodule_path']}"
system "git rm -f #{@config['submodule_path']}"
if File.zero?(".gitmodules")
system "git rm -f .gitmodules"
end
end

def map_folders
mappings = @config["mappings"]
mappings.each do |map|
FileUtils.rm_rf(map["target"])
FileUtils.cp_r(File.join(@config['submodule_path'], map["source"]), map["target"])
end
end

def get_target_folders
target_folders = Array.new

@config["mappings"].each do |map|
target_folders.push(map["target"])
end

return target_folders
end
end
11 changes: 11 additions & 0 deletions helper_tools/submodules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Configuration for the xaml_docs repo
xaml_docs:
remote_ssh: "[email protected]:telerik/xaml-docs.git"
remote_ssl: "https://github.com/telerik/xaml-docs.git"
submodule_path: "xaml_docs"
mappings: [
{ target: "controls/wordsprocessing", source: "controls/radwordsprocessing/." },
{ target: "controls/pdfprocessing", source: "controls/radpdfprocessing/."},
{ target: "controls/ziplibrary", source: "controls/radziplibrary/."},
{ target: "controls/spreadprocessing", source: "controls/radspreadprocessing/."}
]

0 comments on commit c04c1ef

Please sign in to comment.