Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit 4b425b3

Browse files
All is fine
1 parent ca5cbc3 commit 4b425b3

File tree

16 files changed

+578
-159
lines changed

16 files changed

+578
-159
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
!/log/.keep
1414
!/tmp/.keep
1515

16+
/node_modules
17+
1618
# Ignore Byebug command history file.
1719
.byebug_history

README.md

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,97 @@
1-
# README
1+
# Using Postcss in Ruby on Rails - BrowserSync with Gulp
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
3+
## Pasos para configurar
4+
_Aplicación de Rails ya creada_
55

6-
Things you may want to cover:
6+
- Ejecutar `npm init` y configurar el **package.json**
7+
- Instalar gulp localmente `npm install gulp`
8+
- Agregar en el .gitignore la carpeta /node_modules
9+
- Crear archivo **gulpfile.js** en directorio raíz
10+
- En **config/application.rb** requerir los archivos:
11+
config.assets.paths << Rails.root.join("public", "assets", "stylesheets")
12+
config.assets.paths << Rails.root.join("public", "assets", "javascripts")
13+
- En **app/assets/stylesheets/application.css** requerir el archivo de salida que está en public:
14+
`*= require main`
15+
- En **config/environments/development.rb** configurar (para aprovechar BroswerSync):
16+
config.assets.debug = true
17+
config.assets.digest = false
18+
- En **package.json** agregar en *scripts* lo siguiente para limpiar y compilar:
19+
"postinstall": "gulp clean; gulp css;"
20+
- Para usar un plugin de postcss primero se debe instalar usando `npm install --save-dev [nombre_plugin]`
721

8-
* Ruby version
22+
## El archivo gulpfile.js
923

10-
* System dependencies
24+
- Se deben requerir los siguiente módulos:
25+
var gulp = require('gulp')
26+
var postcss = require('gulp-postcss')
27+
var browserSync = require('browser-sync').create()
28+
var del = require('del');
29+
var rename = require('gulp-rename')
30+
- Y adicionalmente las partes de postcss que se desean usar (ver http://postcss.parts):
31+
var rucksack = require('rucksack-css')
32+
var cssnext = require('postcss-cssnext')
33+
var autoprefixer = require('autoprefixer')
34+
var cssnested = require('postcss-nested')
35+
var mixins = require('postcss-mixins')
36+
var lost = require('lost')
37+
var atImport = require('postcss-import')
38+
var csswring = require('csswring')
39+
var materialShadow = require('postcss-material-shadow-helper')
40+
var instagram = require('postcss-instagram')
41+
var coloralpha = require('postcss-color-alpha')
42+
- Deberá tener las siguientes cuatro fuciones principales:
1143

12-
* Configuration
44+
gulp.task('clean', function () {
45+
del('./public/assets/stylesheets');
46+
});
1347

14-
* Database creation
48+
gulp.task('serve', function () {
49+
browserSync.init({
50+
proxy: 'localhost:3000',
51+
files: ['./app/views/**']
52+
})
53+
})
1554

16-
* Database initialization
55+
gulp.task('css', function(){
56+
var processors = [
57+
atImport({
58+
path: ["./gulp/stylesheets"]
59+
}),
60+
cssnested,
61+
lost(),
62+
rucksack(),
63+
cssnext({ browsers: ['> 1%', 'last 3 versions', 'ie 8']}),
64+
materialShadow(),
65+
instagram(),
66+
// csswring()
67+
]
68+
return gulp.src('./gulp/stylesheets/main.css')
69+
.pipe(postcss(processors))
70+
.pipe(gulp.dest('./public/assets/stylesheets'))
71+
.pipe(rename({
72+
suffix: '.self'
73+
}))
74+
.pipe(browserSync.stream() )
75+
})
1776

18-
* How to run the test suite
77+
gulp.task('watch', function(){
78+
gulp.watch('./gulp/stylesheets/*.css', ['css'])
79+
gulp.watch('./app/views/**/*.html').on('change', function(){
80+
browserSync.reload()
81+
})
82+
})
1983

20-
* Services (job queues, cache servers, search engines, etc.)
84+
gulp.task('watch', function(){
85+
gulp.watch('./gulp/stylesheets/*.css', ['css'])
86+
gulp.watch('./app/views/**/*.html').on('change', function(){
87+
browserSync.reload()
88+
})
89+
})
2190

22-
* Deployment instructions
91+
gulp.task('default', ['watch', 'serve'])
2392

24-
* ...
93+
## Consideraciones
94+
95+
Las carpetas del código fuente deberán estar en **/gulp/assets** (crear la carpeta)
96+
97+
Todo lo que deberá ser procesado por Gulp y Postcss Lo compilado irá directo a **/public/assets**

app/assets/stylesheets/application.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* files in this directory. Styles in this file should be added after the last require_* statement.
1111
* It is generally better to create a new file per style scope.
1212
*
13+
*= require main
1314
*= require_tree .
1415
*= require_self
1516
*/

app/assets/stylesheets/scaffolds.scss

Lines changed: 0 additions & 89 deletions
This file was deleted.

app/views/libros/index.html.erb

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
1-
<div class="LibrosIndex">
1+
<h1 class="LibrosIndex-title">LibrosYa! 📚</h1>
22

3-
<div class="LibrosIndex-libros">
3+
<p id="notice"><%= notice %></p>
44

5-
<p id="notice"><%= notice %></p>
5+
<div class="LibrosIndex">
66

7-
<h1>Libros</h1>
7+
<div class="LibrosIndex-libros">
88

9-
<table class="LibrosIndex-table">
10-
<thead>
11-
<tr>
12-
<th>Nombre</th>
13-
<th>Editorial</th>
14-
<th>Portada</th>
15-
<th>Año publicación</th>
16-
<th colspan="3"></th>
17-
</tr>
18-
</thead>
9+
<div class="LibrosIndex-libros-container">
1910

20-
<tbody>
21-
<% @libros.each do |libro| %>
11+
<table class="LibrosIndex-table">
12+
<thead>
2213
<tr>
23-
<td><%= libro.nombre %></td>
24-
<td><%= libro.editorial %></td>
25-
<td><%= image_tag libro.portada.url(:thumb), class:"" %></td>
26-
<td><%= libro.año_publicación %></td>
27-
<td><%= link_to 'Ver', libro, class:"btn btn-principal" %></td>
28-
<td><%= link_to 'Editar', edit_libro_path(libro), class:"btn btn-secundario" %></td>
29-
<td><%= link_to 'Eliminar', libro, method: :delete, data: { confirm: 'Estás seguro?' }, class:"btn btn-peligro" %></td>
14+
<th>Nombre</th>
15+
<th>Editorial</th>
16+
<th>Portada</th>
17+
<th>Año publicación</th>
18+
<th colspan="3"></th>
3019
</tr>
31-
<% end %>
32-
</tbody>
33-
</table>
34-
35-
<br>
20+
</thead>
21+
22+
<tbody>
23+
<% @libros.each do |libro| %>
24+
<tr>
25+
<td><%= libro.nombre %></td>
26+
<td><%= libro.editorial %></td>
27+
<td><%= image_tag libro.portada.url(:thumb), class:"LibrosIndex-table-img" %></td>
28+
<td><%= libro.año_publicación %></td>
29+
<td><%= link_to 'Ver', libro, class:"btn btn-principal" %></td>
30+
<td><%= link_to 'Editar', edit_libro_path(libro), class:"btn btn-secundario" %></td>
31+
<td><%= link_to 'Eliminar', libro, method: :delete, data: { confirm: 'Estás seguro?' }, class:"btn btn-peligro" %></td>
32+
</tr>
33+
<% end %>
34+
</tbody>
35+
</table>
36+
37+
<br>
38+
39+
</div>
3640
</div>
3741

3842
<div class="LibrosIndex-info">
3943

40-
<%= link_to 'Añadir libro', new_libro_path, class:"btn btn-principal" %>
44+
<div class="LibrosIndex-info-container">
45+
<%= link_to '+', new_libro_path, class:"LibrosIndex-info-anadir" %>
46+
</div>
4147

4248
</div>
4349

app/views/libros/show.html.erb

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
1-
<div class="LibrosShow">
1+
<h1 class="LibrosShow-title"> <%= @libro.nombre %> <small> ID:<%= @libro.id %> </small> </h1>
22

33
<p id="notice"><%= notice %></p>
44

5-
<p class="LibrosShow-info">
6-
<strong>Portada:</strong>
7-
<%= image_tag @libro.portada.url(:medium) %>
8-
</p>
9-
10-
<p class="LibrosShow-info">
11-
<strong>Nombre:</strong>
12-
<%= @libro.nombre %>
13-
</p>
14-
15-
<p class="LibrosShow-info">
16-
<strong>Descripción:</strong>
17-
<%= @libro.descripción %>
18-
</p>
19-
20-
<p class="LibrosShow-info">
21-
<strong>Editorial:</strong>
22-
<%= @libro.editorial %>
23-
</p>
24-
25-
<p class="LibrosShow-info">
26-
<strong>Año publicación:</strong>
27-
<%= @libro.año_publicación %>
28-
</p>
29-
30-
<%= link_to 'Editar', edit_libro_path(@libro), class:"btn btn-secundario" %> |
31-
<%= link_to 'Atrás', libros_path, class:"btn btn-cancel" %>
5+
<div class="LibrosShow">
6+
7+
<div class="LibrosShow-portada">
8+
9+
<div class="LibrosShow-imgcontainer">
10+
<%= image_tag @libro.portada.url(:medium), class:"LibrosShow-img" %>
11+
</div>
12+
13+
</div>
14+
15+
<div class="LibrosShow-informacion">
16+
17+
<div class="LibrosShow-informacion-container">
18+
<p class="LibrosShow-info">
19+
<strong>Nombre:</strong>
20+
<%= @libro.nombre %>
21+
</p>
22+
23+
<p class="LibrosShow-info">
24+
<strong>Descripción:</strong>
25+
<%= @libro.descripción %>
26+
</p>
27+
28+
<p class="LibrosShow-info">
29+
<strong>Editorial:</strong>
30+
<%= @libro.editorial %>
31+
</p>
32+
33+
<p class="LibrosShow-info">
34+
<strong>Año publicación:</strong>
35+
<%= @libro.año_publicación %>
36+
</p>
37+
38+
<%= link_to 'Editar', edit_libro_path(@libro), class:"btn btn-secundario" %> |
39+
<%= link_to 'Atrás', libros_path, class:"btn btn-cancel" %>
40+
</div>
41+
</div>
3242

3343
</div>

config/application.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ class Application < Rails::Application
1111
# Settings in config/environments/* take precedence over those specified here.
1212
# Application configuration should go into files in config/initializers
1313
# -- all .rb files in that directory are automatically loaded.
14+
config.assets.paths << Rails.root.join("public", "assets", "stylesheets")
15+
config.assets.paths << Rails.root.join("public", "assets", "javascripts")
1416
end
1517
end

config/environments/development.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# This option may cause significant delays in view rendering with a large
4242
# number of complex assets.
4343
config.assets.debug = true
44+
config.assets.digest = false
4445

4546
# Suppress logger output for asset requests.
4647
config.assets.quiet = true

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Rails.application.routes.draw do
22
resources :libros
33
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
4+
5+
root 'libros#index'
46
end

0 commit comments

Comments
 (0)