middleman-versions 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc29a097675e1b478a5c5dd6064b194f3e0639ff
4
+ data.tar.gz: cdaf29ebcbeae782eea896914007575e36768bbc
5
+ SHA512:
6
+ metadata.gz: 700b08cf243e77f92c3484807eec7b593629ca77f06de26f53dc9c5edfcdf8b684fcf317c3ace38bec369645b5777f5d5a67f0a3fc19468e3f88691c673fb6bb
7
+ data.tar.gz: 4df9e19ba9916467ead7c512513abf23279e31c621328532842fa08a64930dc932da3e44d763d3bca0223b66ab5639e4aedd0c191f329946a41468e626a4e5b3
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
6
+
7
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # If you do not have OpenSSL installed, update
2
+ # the following line to use "http://" instead
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in middleman-versions.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem 'rake'
10
+ gem 'rdoc'
11
+ gem 'yard'
12
+ end
13
+
14
+ group :test do
15
+ gem 'cucumber'
16
+ gem 'aruba'
17
+ gem 'rspec'
18
+ end
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ #middleman-versions
2
+ Compile different middleman site versions with custom data injected in each one
3
+
4
+ ## How to use it
5
+ * Add gem to your Gemfile
6
+
7
+ ```ruby
8
+ gem 'middleman-versions'
9
+ ```
10
+ * Install gems
11
+
12
+ ```ruby
13
+ bundle install
14
+ ```
15
+
16
+ * Edit config.rb and add:
17
+
18
+ ```ruby
19
+ activate :versions do |foo|
20
+ #extension configuration params
21
+ end
22
+ ```
23
+
24
+ ## Extension params:
25
+ | Param name | Description | Type | Default value | Mandatory |
26
+ |----------------------|------------------------------------------------------------|-------------------------------------------------------------------------------------------|---------------|-----------|
27
+ | versions_path | Directory where we have our data files | String | versions/ | Not |
28
+ | versions | List of files that will be treated as versions files | Array of: {:path => "name of file", :decorated_name => "name to be showed in interface"} | Empty | Yes |
29
+ | origin_template | Template where will be injected the data readed from files | String | index.html | Not |
30
+ | destination_template | Name of final compiled file | String | index.html | Not |
31
+
32
+ ## Injected variables on Template
33
+ | Variable name | Description | Type | Example |
34
+ |-----------------|-------------------------------------|---------------|----------------------------------------------------------------------------------------------|
35
+ | versions_paths | List of all versions final paths | Array[String] | ["v1/index.html", "v2/index.html"] |
36
+ | versions_list | List of all version decorated names | Array[String] | ["v1","v2"] |
37
+ | version_data | Data readed from version file | Hash | {"license"=>{"name"=>"Apache 2.0", "url"=>"http://www.apache.org/licenses/LICENSE-2.0.html"}} |
38
+ | current_version | Current version of page itself | String | v1 |
39
+ | current_path | Current final path of page itself | String | v1/index.html |
40
+ |
41
+ ## Compile to static site
42
+ When you execute ````middleman build``` you will get a structure like this
43
+
44
+ ```
45
+ build
46
+ └─── v1
47
+ │ │ index.html
48
+
49
+ └─── v2
50
+ | │ index.html
51
+
52
+ └─── resources
53
+ └─── fonts
54
+ └─── images
55
+ └─── javascripts
56
+ └─── stylesheets
57
+ ```
58
+
59
+
60
+ ## TODO:
61
+ - [ ] Example Middleman project using this gem
62
+ - [ ] Load all files in versions_path and use file name as decorated_name instead of set versions hash
63
+ - [ ] Load subdirectories in versions_path as versions and merge all files inside subdirectory as the same version
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = '--color --tags ~@wip --strict'
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task test: ['cucumber']
13
+
14
+ task default: :test
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require 'middleman-core'
3
+ require 'middleman-core/step_definitions'
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-versions')
@@ -0,0 +1,32 @@
1
+ ---
2
+ routes:
3
+ - url_parameters:
4
+ id: Esta es el id del usuario que queremos modificar
5
+ body:
6
+ mandatory_parameters:
7
+ username:
8
+ validations: Debe tener un numero por que si
9
+ type: String
10
+ password:
11
+ validations: Tiene que ser 1234
12
+ type: String
13
+ email:
14
+ validations: Debe ser de google
15
+ type: String
16
+ optional_parameters:
17
+ aficiones:
18
+ validations: Debe contener 300 caracteres como minimo
19
+ type: String
20
+ example_data:
21
+ username: supertomate@gmail.com
22
+ password: supertomate@gmail.com
23
+ aficiones: supertomate@gmail.com
24
+ email: supertomate@gmail.com
25
+ headers:
26
+ content_type: application/json
27
+ accept: application/json
28
+ method: put
29
+ description: Modificar un usuario
30
+ path: "/users"
31
+ description: Esta es la seccion dedicada a las rutas de usuario. El usuario es cada una de las personas o entes que tienen acceso a una o varias empresas.
32
+ title: Usuario v1
@@ -0,0 +1,46 @@
1
+ {
2
+ "routes": [
3
+ {
4
+ "url_parameters": {
5
+ "id": "Esta es el id del usuario que queremos modificar"
6
+ },
7
+ "body": {
8
+ "mandatory_parameters": {
9
+ "username": {
10
+ "validations": "Debe tener un numero por que si",
11
+ "type": "String"
12
+ },
13
+ "password": {
14
+ "validations": "Tiene que ser 1234",
15
+ "type": "String"
16
+ },
17
+ "email": {
18
+ "validations": "Debe ser de google",
19
+ "type": "String"
20
+ }
21
+ },
22
+ "optional_parameters": {
23
+ "aficiones": {
24
+ "validations": "Debe contener 300 caracteres como minimo",
25
+ "type": "String"
26
+ }
27
+ }
28
+ },
29
+ "example_data": {
30
+ "username": "supertomate@gmail.com",
31
+ "password": "supertomate@gmail.com",
32
+ "aficiones": "supertomate@gmail.com",
33
+ "email": "supertomate@gmail.com"
34
+ },
35
+ "headers": {
36
+ "content_type": "application/json",
37
+ "accept": "application/json"
38
+ },
39
+ "method": "put",
40
+ "description": "Modificar un usuario"
41
+ }
42
+ ],
43
+ "path": "/users",
44
+ "description": "Esta es la seccion dedicada a las rutas de usuario. El usuario es cada una de las personas o entes que tienen acceso a una o varias empresas.",
45
+ "title": "Usuario v2"
46
+ }
@@ -0,0 +1,8 @@
1
+ require 'middleman-core'
2
+
3
+ ::Middleman::Extensions.register(:versions) do
4
+ require_relative "versions/extension"
5
+ require_relative 'versions/version'
6
+ require_relative 'versions/helpers/file_handler'
7
+ ::Middleman::VersionsExtension
8
+ end
@@ -0,0 +1,35 @@
1
+ module Middleman
2
+ class VersionsExtension < ::Middleman::Extension
3
+ option :versions_path, 'versions/', 'Directory path where we search the versions'
4
+ option :versions, [], 'Array of hashes, {:path => "name of file", :decorated_name => "name to be showed in interface"}'
5
+ option :origin_template, 'index.html', 'Template where data will be inserted the data'
6
+ option :destination_template, 'index.html', 'Compiled template name'
7
+
8
+ def initialize(app, options_hash={}, &block)
9
+ super
10
+ end
11
+
12
+
13
+ def after_configuration
14
+ app.config[:versions_options] = options
15
+ versions_list = options.versions.map{|x| x[:decorated_name]}
16
+ versions_paths = options.versions.map{|x| x[:decorated_name] + "/" + options.destination_template}
17
+
18
+ options.versions.each do |version|
19
+ full_version_path = options.versions_path + version[:path]
20
+ version_data = Versions::FileHandler::load_file(full_version_path)
21
+ current_path = "#{version[:decorated_name]}/#{options.destination_template}"
22
+
23
+ app.proxy "#{current_path}", "/#{options.origin_template}",
24
+ :locals => {
25
+ :versions_paths => versions_paths,
26
+ :versions_list => versions_list,
27
+ :version_data => version_data ,
28
+ :current_version => version[:decorated_name],
29
+ :current_path => "#{current_path}"
30
+ },
31
+ :ignore => true
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ module Middleman
2
+ module Versions
3
+ module FileHandler
4
+ def self.load_file(path)
5
+ case File.extname(path)
6
+ when ".yml",".yaml"
7
+ load_yaml_file path
8
+ when ".json"
9
+ load_json_file path
10
+ end
11
+ end
12
+
13
+ private_class_method def self.load_yaml_file(path)
14
+ require 'yaml'
15
+ YAML::load(File.open(path))
16
+ end
17
+
18
+ private_class_method def self.load_json_file(path)
19
+ require 'json'
20
+ JSON.parse( IO.read(path))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Versions
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require_relative 'middleman/middleman-versions'
@@ -0,0 +1 @@
1
+ require 'middleman-versions'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "middleman-versions"
6
+ s.version = "1.0.0"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Pedro Rivas", "Cuéntica","Guillermo Latorre", "David Olmos"]
9
+ s.email = ["rmdrobs@gmail.com", "contacto@cuentica.com", "superwillyfoc@gmail.com", "olmos.david@gmail.com"]
10
+ s.homepage = "https://github.com/cuentica/middleman-versions.git"
11
+ s.summary = %q{Compile different middleman versions with custom data injected in each one}
12
+ s.description = %q{Compile different middleman versions with custom data injected in each one}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # The version of middleman-core your extension depends on
20
+ s.add_runtime_dependency("middleman-core", [">= 4.0.0"])
21
+
22
+ # Additional dependencies
23
+ # s.add_runtime_dependency("gem-name", "gem-version")
24
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+ require_relative '../lib/middleman/versions/helpers/file_handler'
3
+
4
+ describe "FileHandler" do
5
+ it "load_file method must return a non empty hash from json file" do
6
+ version_hash = Middleman::Versions::FileHandler::load_file(File.join(File.dirname(__FILE__),"../fixtures/directory_with_files/v2.json"))
7
+ expect(version_hash).to include({"title" => "Usuario v2"})
8
+ end
9
+ it "load_file method must return a non empty hash from yml file" do
10
+ version_hash = Middleman::Versions::FileHandler::load_file(File.join(File.dirname(__FILE__),"../fixtures/directory_with_files/v1.yml"))
11
+ expect(version_hash).to include({"title" => "Usuario v1"})
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-versions
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Rivas
8
+ - Cuéntica
9
+ - Guillermo Latorre
10
+ - David Olmos
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2016-11-14 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: middleman-core
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ description: Compile different middleman versions with custom data injected in each
31
+ one
32
+ email:
33
+ - rmdrobs@gmail.com
34
+ - contacto@cuentica.com
35
+ - superwillyfoc@gmail.com
36
+ - olmos.david@gmail.com
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - ".gitignore"
42
+ - Gemfile
43
+ - README.md
44
+ - Rakefile
45
+ - features/support/env.rb
46
+ - fixtures/directory_with_files/v1.yml
47
+ - fixtures/directory_with_files/v2.json
48
+ - lib/middleman-versions.rb
49
+ - lib/middleman/middleman-versions.rb
50
+ - lib/middleman/versions/extension.rb
51
+ - lib/middleman/versions/helpers/file_handler.rb
52
+ - lib/middleman/versions/version.rb
53
+ - lib/middleman_extension.rb
54
+ - middleman-versions.gemspec
55
+ - spec/file_handler_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: https://github.com/cuentica/middleman-versions.git
58
+ licenses: []
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.5.1
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Compile different middleman versions with custom data injected in each one
80
+ test_files: []