alchemy-site_bootstrapping 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c877581e94b040cacb9e39a21023f9d47f904fc1
4
+ data.tar.gz: eee53de1a5288ff8b146462fad1cc092f9aa7eed
5
+ SHA512:
6
+ metadata.gz: 0643f4c2d1e79d1852b091662d12701546d8818fadd5d1e80ae37ebc0521984330ac65ea37d6c97c5b2ee584e23f0808d00c3474c850230d14a1701cf971d706
7
+ data.tar.gz: 7d2c3fe0b92ced4b41ae4f1ec98de4620211369c1a75152f110724186fc0f4823eb85b9378fd7657ac78627dbbe6c72601940dc23af093f347d029a96f6932e6
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ .bundle/
3
+ log/*.log
4
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in alchemy-site_bootstrapping.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ alchemy-site_bootstrapping (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (11.1.2)
11
+ rspec (2.99.0)
12
+ rspec-core (~> 2.99.0)
13
+ rspec-expectations (~> 2.99.0)
14
+ rspec-mocks (~> 2.99.0)
15
+ rspec-core (2.99.2)
16
+ rspec-expectations (2.99.2)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.99.4)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ alchemy-site_bootstrapping!
25
+ bundler (~> 1.3)
26
+ rake
27
+ rspec (~> 2.14)
28
+
29
+ BUNDLED WITH
30
+ 1.11.2
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Robin Böning
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Bootstrap your Alchemy sites
2
+
3
+ This gem allows you to use different stylesheets and javascripts for each of your alchemy sites.
4
+
5
+ If you are running a multi-site environment with Alchemy CMS and you want to make those sites look and bwehave different from each other, this gem is a good fit for you.
6
+
7
+ # How to use the gem
8
+
9
+ 1. The gem provides a site generator which creates the site in your database and also generates the manifest files for the site specific stylesheets and javascripts.
10
+
11
+ Create a new site
12
+
13
+ ```
14
+ $ rails g alchemy:site blog localhost
15
+ ```
16
+
17
+ The generator will create a new site called blog that runs on localhost.
18
+
19
+ It also creates a CSS manifest file `app/assets/stylesheets/blog.scss`. By default this file imports all files from `app/assets/stylesheets/alchemy/sites/blog/` folder and will be considered to be precompiled in production.
20
+
21
+ It also creates a Javascript manifest file `app/assets/javascripts/blog.js`. By default this file requires all files from `app/assets/javascripts/alchemy/sites/blog/` folder and will be considered to be precompiled in production.
22
+
23
+
24
+ 2. The gem also provides view helpers to render the right stylesheet or javascript in your layout. If for whatever reason it can not find the right file it will fall back to `application.js/css`.
25
+
26
+
27
+ To render site specific stylesheets simply pass `stylesheet_for_current_site` to `stylesheet_link_tag`.
28
+
29
+ ```
30
+ <%= stylesheet_link_tag stylesheet_for_current_site, media: 'all' %>
31
+ ```
32
+
33
+ To render site specific javascripts simply pass `javascript_for_current_site` to `javascript_include_tag`.
34
+
35
+ ```
36
+ <%= javascript_include_tag javascript_for_current_site %>
37
+ ```
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Alchemy::SiteBootstrapping'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alchemy/site_bootstrapping/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alchemy-site_bootstrapping"
8
+ spec.version = Alchemy::SiteBootstrapping::VERSION
9
+ spec.authors = ["Robin Böning"]
10
+ spec.email = ["robin.boening@bitspire.de"]
11
+ spec.description = %q{Bootstrap your Alchemy sites}
12
+ spec.summary = %q{Bootstrap your Alchemy sites}
13
+ spec.homepage = "https://bitspire.de"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path(File.expand_path('../../test', __FILE__))
3
+
4
+ require 'bundler/setup'
5
+ require 'rails/test_unit/minitest_plugin'
6
+
7
+ Rails::TestUnitReporter.executable = 'bin/test'
8
+
9
+ exit Minitest.run(ARGV)
@@ -0,0 +1,7 @@
1
+ require "alchemy/site_bootstrapping/view_helpers"
2
+ require "alchemy/site_bootstrapping/engine"
3
+
4
+ module Alchemy
5
+ module SiteBootstrapping
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ module Alchemy
2
+ module SiteBootstrapping
3
+
4
+ class Engine < Rails::Engine
5
+
6
+ # Collecting stylesheets in app/assets/stylesheets
7
+ initializer "alchemy.assign_stylesheets_for_sites" do |app|
8
+ app.config.stylesheets_for_alchemy_sites =
9
+ Dir.glob(File.join(Rails.root, "app/assets/stylesheets/*.scss"))
10
+ end
11
+
12
+ # Stylesheets defined for Sites will be precompiled.
13
+ initializer 'alchemy.stylesheets_for_sites_to_precompile' do |app|
14
+ app.config.stylesheets_for_alchemy_sites.each do |file_path|
15
+ app.config.assets.precompile << "#{File.basename(file_path, '.scss')}.css"
16
+ end
17
+ end
18
+
19
+ # Collecting javascripts in app/assets/javascripts
20
+ initializer "alchemy.assign_javascripts_for_sites" do |app|
21
+ app.config.javascripts_for_alchemy_sites =
22
+ Dir.glob(File.join(Rails.root, "app/assets/javascripts/*.js"))
23
+ end
24
+
25
+ # Javascripts defined for Sites will be precompiled.
26
+ initializer 'alchemy.javascripts_for_sites_to_precompile' do |app|
27
+ app.config.javascripts_for_alchemy_sites.each do |file_path|
28
+ app.config.assets.precompile << "#{File.basename(file_path, '.js')}.js"
29
+ end
30
+ end
31
+
32
+ # Make helper methods available to use correct stylesheet for each particular site
33
+ initializer "alchemy.sitebootstrapping.view_helpers" do
34
+ ActionView::Base.send :include, ViewHelpers
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module Alchemy
2
+ module SiteBootstrapping
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ module Alchemy
2
+ module SiteBootstrapping
3
+ module ViewHelpers
4
+
5
+ # In your layout file use this view helper to render the stylesheet for the currently requested site
6
+ # Usage: `stylesheet_link_tag stylesheet_for_current_site, media: 'all'`
7
+ def stylesheet_for_current_site
8
+ site_has_stylesheet?(current_site_name) ? current_site_name.parameterize : "application"
9
+ end
10
+
11
+ def site_has_stylesheet?(site_name)
12
+ stylesheets = Rails.application.config.stylesheets_for_alchemy_sites
13
+ stylesheets.map { |f| File.basename(f) }.include? "#{site_name.parameterize}.scss"
14
+ end
15
+
16
+ # In your layout file use this view helper to render the javascript for the currently requested site
17
+ # Usage: `javascript_include_tag javascript_include_tag`
18
+ def javascript_for_current_site
19
+ site_has_javascript?(current_site_name) ? current_site_name.parameterize : "application"
20
+ end
21
+
22
+ def site_has_javascript?(site_name)
23
+ javascripts = Rails.application.config.javascripts_for_alchemy_sites
24
+ javascripts.map { |f| File.basename(f) }.include? "#{site_name.parameterize}.js"
25
+ end
26
+
27
+ def current_site_name
28
+ @current_site_name ||= Alchemy::Site.current.name
29
+ end
30
+
31
+ def favicon_path(filename)
32
+ asset_path "favicon/#{current_site_name.parameterize}/#{filename}"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ require 'rails'
2
+
3
+ module Alchemy
4
+ module Generators
5
+ class SiteGenerator < ::Rails::Generators::Base
6
+ desc "This generator generates your site and its corresponding asset structure."
7
+ argument :site_name, banner: "Site-Name"
8
+ argument :site_host, banner: "site-host.com"
9
+ source_root File.expand_path('templates', File.dirname(__FILE__))
10
+
11
+ def init
12
+ @site_name = site_name
13
+ @parameterized_site_name = site_name.parameterize
14
+ @site_host = site_host
15
+ end
16
+
17
+ def create_site
18
+ site = Alchemy::Site.find_or_initialize_by(name: @site_name, host: @site_host)
19
+ if site.persisted?
20
+ puts "Site #{@site_name} already exists. Skipping creation of Site."
21
+ else
22
+ site.save!
23
+ puts "Created Site #{@site_name} (unpublished)."
24
+ end
25
+ end
26
+
27
+ def create_stylesheets
28
+ puts "Creating directories and files for site related stylesheets..."
29
+ root_css_dir = "#{Rails.root}/app/assets/stylesheets"
30
+ namespaced_site_dir = "#{root_css_dir}/alchemy/sites/#{@parameterized_site_name}"
31
+ empty_directory namespaced_site_dir
32
+ template "site.scss", "#{root_css_dir}/#{@parameterized_site_name}.scss"
33
+ template "_variables.scss", "#{namespaced_site_dir}/_variables.scss"
34
+ end
35
+
36
+ def create_javascripts
37
+ puts "Creating directories and files for site related javascripts..."
38
+ root_js_dir = "#{Rails.root}/app/assets/javascripts"
39
+ empty_directory "#{root_js_dir}/alchemy/sites/#{@parameterized_site_name}"
40
+ template "site.js", "#{root_js_dir}/#{@parameterized_site_name}.js"
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1 @@
1
+ // Add <%= @site_name %> specific variables here
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into <%= @parameterized_site_name %>.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree ./alchemy/sites/<%= @parameterized_site_name %>
@@ -0,0 +1,34 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into <%= @parameterized_site_name %>.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_self
14
+ */
15
+
16
+ // This file was created by a generator provided by the alchemy-site_bootstrapping gem.
17
+
18
+ // // From our best practise: Site specific variables for <%= @site_name %>
19
+ @import "alchemy/sites/<%= @parameterized_site_name %>/variables";
20
+
21
+ // From our best practise: All global settings and default variables
22
+ // @import "global/settings";
23
+
24
+ // <%= @site_name %> fonts
25
+ // @import "alchemy/sites/<%= @parameterized_site_name %>/fonts";
26
+
27
+ // From our best practise: All other global styles
28
+ // @import "global/*";
29
+
30
+ // Styling for Alchemy elements
31
+ // @import "alchemy/elements/*";
32
+
33
+ // <%= @site_name %> specific styles
34
+ // @import "alchemy/sites/<%= @parameterized_site_name %>/*";
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :alchemy_site_bootstrapping do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alchemy-site_bootstrapping
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robin Böning
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ description: Bootstrap your Alchemy sites
56
+ email:
57
+ - robin.boening@bitspire.de
58
+ executables:
59
+ - test
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - MIT-LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - alchemy_site_bootstrapping.gemspec
70
+ - bin/test
71
+ - lib/alchemy/site_bootstrapping.rb
72
+ - lib/alchemy/site_bootstrapping/engine.rb
73
+ - lib/alchemy/site_bootstrapping/version.rb
74
+ - lib/alchemy/site_bootstrapping/view_helpers.rb
75
+ - lib/rails/generators/alchemy/site/site_generator.rb
76
+ - lib/rails/generators/alchemy/site/templates/_variables.scss
77
+ - lib/rails/generators/alchemy/site/templates/site.js
78
+ - lib/rails/generators/alchemy/site/templates/site.scss
79
+ - lib/tasks/alchemy/site_bootstrapping_tasks.rake
80
+ homepage: https://bitspire.de
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.5.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Bootstrap your Alchemy sites
104
+ test_files: []