diff --git a/Gemfile b/Gemfile index af6cfd8..6f34b4a 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ gem 'rake' # Component requirements gem 'activerecord', '>= 3.1', :require => 'active_record' gem 'sqlite3' - +gem 'haml' # Test requirements # Padrino Stable Gem diff --git a/Gemfile.lock b/Gemfile.lock index 455c003..193446a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,6 +17,8 @@ GEM arel (6.0.3) builder (3.2.2) enumerable-lazy (0.0.1) + haml (4.0.7) + tilt i18n (0.7.0) json (1.8.3) mail (2.6.4.rc2) @@ -80,6 +82,7 @@ PLATFORMS DEPENDENCIES activerecord (>= 3.1) + haml padrino (= 0.13.1) rake sqlite3 diff --git a/app/controllers/badge.rb b/app/controllers/badge.rb new file mode 100644 index 0000000..2dd18cf --- /dev/null +++ b/app/controllers/badge.rb @@ -0,0 +1,23 @@ +Embadge::App.controllers :badge do + + # get :index, :map => '/foo/bar' do + # session[:foo] = 'bar' + # render 'index' + # end + + # get :sample, :map => '/sample/url', :provides => [:any, :js] do + # case content_type + # when :js then ... + # else ... + # end + + # get :foo, :with => :id do + # "Maps to url '/foo/#{params[:id]}'" + # end + + # get '/example' do + # 'Hello world!' + # end + + +end diff --git a/app/controllers/static.rb b/app/controllers/static.rb new file mode 100644 index 0000000..6d03d94 --- /dev/null +++ b/app/controllers/static.rb @@ -0,0 +1,8 @@ +Embadge::App.controllers :static do + + get :index, map: '/' do + render :index + end + + +end diff --git a/app/helpers/badge_helper.rb b/app/helpers/badge_helper.rb new file mode 100644 index 0000000..03dbae0 --- /dev/null +++ b/app/helpers/badge_helper.rb @@ -0,0 +1,13 @@ +# Helper methods defined here can be accessed in any controller or view in the application + +module Embadge + class App + module BadgeHelper + # def simple_helper_method + # ... + # end + end + + helpers BadgeHelper + end +end diff --git a/app/helpers/static_helper.rb b/app/helpers/static_helper.rb new file mode 100644 index 0000000..3b42a2c --- /dev/null +++ b/app/helpers/static_helper.rb @@ -0,0 +1,13 @@ +# Helper methods defined here can be accessed in any controller or view in the application + +module Embadge + class App + module StaticHelper + # def simple_helper_method + # ... + # end + end + + helpers StaticHelper + end +end diff --git a/app/views/layouts/application.haml b/app/views/layouts/application.haml new file mode 100644 index 0000000..28d4a5a --- /dev/null +++ b/app/views/layouts/application.haml @@ -0,0 +1,12 @@ +!!! +%html + %head + %title embadge.io + %link{:href => "//fonts.googleapis.com/css?family=Source+Sans+Pro:400,700", :rel => "stylesheet", :type => "text/css"}/ + %link{:href => "/css/main.css", :rel => "stylesheet", :type => "text/css"}/ + %body + %a{:href => "https://github.com/halfdan/embadge.io"} + %img{:alt => "Fork me on GitHub", :src => "https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png", :style => "position: absolute; top: 0; right: 0; border: 0;"}/ + #content + %h1 embadge.io + %main= yield diff --git a/app/views/static/index.haml b/app/views/static/index.haml new file mode 100644 index 0000000..3d06002 --- /dev/null +++ b/app/views/static/index.haml @@ -0,0 +1,74 @@ +%p + embadge.io is a simple Ember.js badge generator service. + It provides a simple to use API. + It's inspired by Matthew Beale'sĀ  + %a{:href => "https://github.com/mixonic/ember-community-versions"} Ember Community Versions + and is open-sourcedĀ  + %a{:href => "https://github.com/halfdan/embadge.io"} on Github +%h2#examples Examples +%ul + %li + With start version: + %br/ + %a{:href => "//embadge.io/v1/badge.svg?start=1.13.0"} + %img{:src => "//embadge.io/v1/badge.svg?start=1.13.0"}/ + %li + With start and end version: + %br/ + %a{:href => "//embadge.io/v1/badge.svg?start=1.13.0&end=2.0.0"} + %img{:src => "//embadge.io/v1/badge.svg?start=1.13.0&end=2.0.0"}/ + %li + With range: + %br/ + %a{:href => "//embadge.io/v1/badge.svg?range=^2.3.0"} + %img{:src => "//embadge.io/v1/badge.svg?range=^2.3.0"}/ + %li + With custom label: + %br/ + %a{:href => "//embadge.io/v1/badge.svg?label=ember-cli&start=1.13.13"} + %img{:src => "//embadge.io/v1/badge.svg?label=ember-cli&start=1.13.13"}/ + %li + With custom label and range: + %br/ + %a{:href => "//embadge.io/v1/badge.svg?label=ember-data&range=^2.3.0"} + %img{:src => "//embadge.io/v1/badge.svg?label=ember-data&range=^2.3.0"}/ +%h2#usage Usage +%p The embadge.io API supports four different parameters. +%ul + %li + %pre> label + Used to define the text label shown on the badge (default: 'ember-versions') + %li + %pre> start + Valid semver string noting the earliest supported version. + %li + %pre> end + (Optional) Valid semver string noting the last supported version. + %li + %pre> range + (Optional) Valid semver range (e.g. "^2.3.0") noting a supported range of versions. If given, + %code start + and + %code end + will be ignored. +%p + The API supports HTTPS and is accessed from is + %code https://embadge.io/v1/badge.svg +%h3#browser Browser +%p In order to easily add embadge.io to your website you can include the following script in the body: +%code + %pre +%p + This will search your page for + %code span + elements with the + %code embadge + class and use data attributes to generate the image URL. +%code + %pre +%h2#links Links +%ul + %li + %a{:href => "http://emberup.co/dynamic-component-rendering/"} Dynamic component rendering + %li + %a{:href => "https://github.com/mixonic/ember-community-versions"} Ember Community Versions diff --git a/public/css/main.css b/public/css/main.css new file mode 100644 index 0000000..92b0f95 --- /dev/null +++ b/public/css/main.css @@ -0,0 +1,54 @@ +*, *:before, *:after { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +body { + background: white; + font-family: 'Georgia', serif; + margin: 0; + padding: 0; +} + +#content { + max-width: 600px; + margin: 0 auto; + position: relative; + padding: 20px; +} + +h1, h2 { + font-family: 'Source Sans Pro', sans-serif; +} + +h1 { + font-size: 72px; + line-height: 1.7; + margin: 0; + padding: 0; + +} + +h2 { + color: #333; +} + +p { + color: #444; + line-height: 1.6; + font-size: 18px; +} + +li { + line-height: 1.6; + font-size: 18px; +} + +a { + color: #d01040; +} + +a:visited { + color: rgba(208, 16, 64, 0.6); +} diff --git a/public/v1/badge.js b/public/v1/badge.js new file mode 100644 index 0000000..a1667f6 --- /dev/null +++ b/public/v1/badge.js @@ -0,0 +1,17 @@ +(function() { + var elements = document.getElementsByClassName('embadge'), + url = '//embadge.io/v1/badge.svg'; + for (i=0; i < elements.length; i++) { + var img = document.createElement('img'), + el = elements[i]; + if (el.dataset.range) { + img.src = url + '?range=' + el.dataset.range; + } else { + img.src = url + '?start=' + el.dataset.start; + if (el.dataset.end) { + img.src += '&end=' + el.dataset.end; + } + } + el.appendChild(img); + }; +})();