roger_themes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bce0af5e073b8ec748ab99636295b43d8764c2e8
4
+ data.tar.gz: 45a91b6a5d59d925ae3ef4e969de0225dbb61bb4
5
+ SHA512:
6
+ metadata.gz: 723ed580109365f22b364214a8e238ff181fe4a2845270e4d830e21eb35ffffd5714da1865e85b12867fd7c39cdecbfda8f687f5c5d12feb4033df9cdfedbe7d
7
+ data.tar.gz: c9f3d9cdab3a033c21d8448be76e0114374d9dee74143814c5ddf44f611c9f48b07768311b3b475ca95a44010b2c567f7a2a129f5ff904ba6ab8cd8ac69255b4
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rubocop ADDED
@@ -0,0 +1,3 @@
1
+ # Don't give me rails thingies
2
+ AllCops:
3
+ RunRailsCops: false
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in roger_themes.gemspec
4
+ gemspec
5
+
6
+ gem "pry"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Edwin van der Graaf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # RogerThemes
2
+
3
+ Create themes and release them as static site.
4
+
5
+ ## Themes setup
6
+
7
+ Your themes live in the themes dir, it will release all pages for your themes
8
+ into the theme dir.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'roger_themes'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+
23
+ ## Todo
24
+
25
+ - [] Add tests
26
+ - [] Complete documentation (especially on how themes work by default)
27
+ - [] Add theme selector views for usage in table of content
28
+
29
+ ## Usage
30
+
31
+ Include the middleware and processor in the `serve` and `release` block:
32
+
33
+ ```
34
+ mockup.serve do |s|
35
+ s.use RogerThemes::Middleware
36
+ # ...
37
+ end
38
+ ```
39
+
40
+ ```
41
+ mockup.release do |r|
42
+ # ..
43
+ r.use :themes
44
+
45
+ # Finalise your zips for XC
46
+ r.finalize RogerThemes::XcFinalizer
47
+ ```
48
+
49
+ ## Changelog
50
+
51
+ ### v0.1.0
52
+
53
+ * `:shared_folders` now also takes a hash to enable nested theme folders
54
+ ```
55
+ {
56
+ shared_folders: {"images" => "rel/images"}
57
+ }
58
+ ```
59
+ * Remove `rel` from shared_folders
60
+
61
+ ### v0.0.1 (never released)
62
+
63
+ * Initial release
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( https://github.com/digitpaint/roger_themes/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rubocop/rake_task"
4
+
5
+ task default: [:test, :rubocop]
6
+
7
+ desc "Run rubocop"
8
+ task :rubocop do
9
+ RuboCop::RakeTask.new
10
+ end
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.libs << "test"
14
+ t.test_files = FileList["test/*_test.rb"]
15
+ t.verbose = false
16
+ end
@@ -0,0 +1,9 @@
1
+ require "roger_themes/version"
2
+
3
+ module RogerThemes
4
+ # Your code goes here...
5
+ end
6
+
7
+ require "roger_themes/middleware"
8
+ require "roger_themes/processor"
9
+ require "roger_themes/xc_finalizer"
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/shared_folders"
2
+
3
+ module RogerThemes
4
+ class Middleware
5
+ def initialize(app, options = {})
6
+ @app = app
7
+
8
+ defaults = {
9
+ default_theme: "default",
10
+ shared_folders: ["images", "fonts"]
11
+ }
12
+
13
+ @options = defaults.update(options)
14
+ @shared_folders = SharedFolders.new(@options[:shared_folders])
15
+ end
16
+
17
+ def call(env)
18
+ path = ::Rack::Utils.unescape(env["PATH_INFO"])
19
+ r = /\A\/themes\/([^\/]+)\/theme\//
20
+ if theme = path[r,1]
21
+ orig_path = env["PATH_INFO"].dup
22
+ env["SITE_THEME"] = theme
23
+ env["PATH_INFO"].sub!(r,"")
24
+ else
25
+ # Set default theme
26
+ env["SITE_THEME"] = @options[:default_theme]
27
+ end
28
+
29
+ ret = @app.call(env)
30
+
31
+ # Fallback for shared images
32
+ unless ret[0] == 200
33
+
34
+ shared_path = @shared_folders.local_to_shared_path(path)
35
+
36
+ if shared_path
37
+ # Store so we can restore later
38
+ orig_path = env["PATH_INFO"].dup
39
+ env["PATH_INFO"] = shared_path
40
+ end
41
+
42
+ ret = @app.call(env)
43
+
44
+ # Restore path so we are nice with everybody else
45
+ env["PATH_INFO"] = orig_path
46
+ end
47
+
48
+ ret
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,83 @@
1
+ require "roger/release/processors/mockup"
2
+
3
+ module RogerThemes
4
+ class Processor < Roger::Release::Processors::Base
5
+ def initialize(options = {})
6
+
7
+ defaults = {
8
+ default_theme: 'default',
9
+ excludes: [
10
+ /\A_doc\/.*/,
11
+ /\Athemes\/.*/,
12
+ "index.html"
13
+ ],
14
+ shared_folders: ["images", "fonts"]
15
+ }
16
+
17
+ @options = defaults.update(options)
18
+ end
19
+
20
+ def call(release, options)
21
+ @options = @options.dup.update(options)
22
+
23
+ files_glob = "**/*{.html,.html.erb}"
24
+
25
+ themes = []
26
+
27
+ Dir.chdir(release.build_path) do
28
+ Dir.chdir("themes") do
29
+ themes = Dir.glob("*").select{|d| File.directory?(d) }.map{|t| [t, Pathname.new("themes/#{t}/theme")] }
30
+ end
31
+
32
+ # Get files from html path
33
+ files = Dir.glob("../html/#{files_glob}").map{ |f| f.sub("../html/", "") }
34
+ files.reject!{|c| @options[:excludes].detect{|e| e.match(c) } }
35
+
36
+ release.debug self, "Copying theme files #{files.inspect}"
37
+
38
+ themes.each do |theme, theme_dir|
39
+ mkdir_p theme_dir
40
+
41
+ files.each do |file|
42
+ mkdir_p theme_dir + File.dirname(file)
43
+ cp release.project.html_path + file, theme_dir + file
44
+ end
45
+ end
46
+ end
47
+
48
+ # Run mockup for each theme
49
+ themes.each do |theme, theme_dir|
50
+ match_glob = theme_dir + files_glob
51
+
52
+ mockup_processor = Roger::Release::Processors::Mockup.new({
53
+ match: [match_glob],
54
+ env: {
55
+ "SITE_THEME" => theme,
56
+ "MOCKUP_PROJECT" => release.project
57
+ }
58
+ })
59
+ mockup_processor.call(release)
60
+
61
+ # cp html/images and html/fonts => html/themes/**/images && html/themes/**/fonts
62
+ # if not in target dir
63
+ # well conceptual not complete, doing so would required scanning all HTML and
64
+ # CSS I suppose.
65
+ #
66
+ # This means that it could be possible to get images that are not used within the
67
+ # zip, since these are not requried in css it wouln't cause any problems thou
68
+ # the zip size does increase
69
+ #
70
+ # Behavior must be simialir to the rewrite in processor
71
+ release.debug self, "Starting assets copy for #{@options[:shared_folders]}"
72
+ shared_folders = SharedFolders.new(@options[:shared_folders])
73
+
74
+ Dir.chdir(release.build_path + "themes/#{theme}") do
75
+ release.debug self, "Copying assets for #{theme}"
76
+ shared_folders.folders.each do |copy_from, copy_to|
77
+ cp_r release.build_path + copy_from, copy_to
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,32 @@
1
+ module RogerThemes
2
+ class SharedFolders
3
+ def initialize(folders)
4
+ # To allow shared_folders to passed in as array
5
+ # in cases the mapping becomes 1:1 update shared_folders to Hash
6
+ if folders.is_a? Array
7
+ paths = folders.map { |v| [v, v] }
8
+ @folders = Hash[paths]
9
+ else
10
+ @folders = folders
11
+ end
12
+ end
13
+
14
+ # Takes an local theme path
15
+ # and tries to resolve this to
16
+ # shared path
17
+ def local_to_shared_path(path)
18
+ matched_shared = @folders.detect do |folder_to, folder_from|
19
+ if path[/\A\/themes\/([^\/]+)\/#{folder_from}\//, 1]
20
+ [folder_to, folder_from]
21
+ end
22
+ end
23
+
24
+ if matched_shared
25
+ path.sub(/\A\/themes\/([^\/]+)\/#{matched_shared[1]}/,
26
+ "/#{matched_shared[0]}")
27
+ else
28
+ false
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module RogerThemes
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ module RogerThemes
2
+ class XcFinalizer < Roger::Release::Finalizers::Base
3
+ attr_reader :release
4
+
5
+ def call(release, options = {})
6
+ dirs = Dir.glob((release.build_path + "themes/*").to_s)
7
+
8
+ options = {
9
+ :prefix => "html",
10
+ :zip => "zip"
11
+ }.update(options)
12
+
13
+ releasename = [(options[:prefix] || "html"), release.scm.version].join("-")
14
+
15
+ zipdir = release.build_path + "themes/zips"
16
+ FileUtils.mkdir_p(zipdir) unless zipdir.exist?
17
+
18
+ dirs.each do |dir|
19
+ name = File.basename(dir)
20
+ path = Pathname.new(dir)
21
+
22
+ begin
23
+ `#{options[:zip]} -v`
24
+ rescue Errno::ENOENT
25
+ raise RuntimeError, "Could not find zip in #{options[:zip].inspect}"
26
+ end
27
+
28
+ ::Dir.chdir(path) do
29
+ `#{options[:zip]} -r -9 "#{zipdir + name}-#{release.scm.version}.zip" rel js`
30
+ end
31
+
32
+ release.log(self, "Creating zip for custom #{name}")
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "roger_themes/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "roger_themes"
8
+ spec.version = RogerThemes::VERSION
9
+ spec.authors = ["Edwin van der Graaf"]
10
+ spec.email = ["edwin@digitpaint.nl"]
11
+ spec.summary = "Create themes and release them as static site"
12
+ spec.homepage = "https://github.com/digitpaint/roger_themes"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "roger", "~> 1.0"
21
+ spec.add_dependency "rack"
22
+
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "test-unit", "~> 3.1.2"
25
+ spec.add_development_dependency "simplecov", "~> 0.10.0"
26
+ spec.add_development_dependency "rubocop", "~> 0.31.0"
27
+ end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+ require "./lib/roger_themes/middleware"
3
+
4
+ require "rack/mock"
5
+
6
+ module RogerThemes
7
+ class TestMiddleware < ::Test::Unit::TestCase
8
+
9
+ def setup
10
+ @app = proc { [200, {}, ["YAM"]] } # Yet another middleware
11
+ @middleware = Middleware.new @app
12
+
13
+ @request = Rack::MockRequest.new(@middleware)
14
+ end
15
+
16
+ def test_middleware_can_be_called
17
+ assert(@middleware.respond_to?(:call))
18
+ end
19
+
20
+ def test_doesnt_touch_other_requests
21
+ assert_equal @request.get("/my.js").body, "YAM"
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ require "test_helper"
2
+ require "./lib/roger_themes/shared_folders"
3
+
4
+ require "rack/mock"
5
+
6
+ module RogerThemes
7
+ class TestSharedFolders < ::Test::Unit::TestCase
8
+ def setup
9
+ @shared_folders = SharedFolders.new(["images", "fonts"])
10
+ end
11
+
12
+ def test_simple_case_with_array
13
+ shared_path = @shared_folders.local_to_shared_path("/themes/default/fonts/")
14
+ assert_equal "/fonts/", shared_path
15
+ end
16
+
17
+ def test_with_hash
18
+ @shared_folders = SharedFolders.new("fonts" => "rel/fonts",
19
+ "images" => "rel/images")
20
+
21
+ shared_path = @shared_folders.local_to_shared_path("/themes/default/rel/fonts/")
22
+ assert_equal "/fonts/", shared_path
23
+ end
24
+
25
+ def test_returns_false_when_no_shared_folder
26
+ shared_path = @shared_folders.local_to_shared_path("/themes/default/not_found/")
27
+ assert !shared_path
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
4
+ require "test/unit"
5
+ require "pry"
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roger_themes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Edwin van der Graaf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.31.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.31.0
97
+ description:
98
+ email:
99
+ - edwin@digitpaint.nl
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/roger_themes.rb
111
+ - lib/roger_themes/middleware.rb
112
+ - lib/roger_themes/processor.rb
113
+ - lib/roger_themes/shared_folders.rb
114
+ - lib/roger_themes/version.rb
115
+ - lib/roger_themes/xc_finalizer.rb
116
+ - roger_themes.gemspec
117
+ - test/middleware_test.rb
118
+ - test/shared_folders_test.rb
119
+ - test/test_helper.rb
120
+ homepage: https://github.com/digitpaint/roger_themes
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Create themes and release them as static site
144
+ test_files:
145
+ - test/middleware_test.rb
146
+ - test/shared_folders_test.rb
147
+ - test/test_helper.rb