Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
28d666d8
Commit
28d666d8
authored
Jun 05, 2013
by
Calen Pennington
Committed by
Jason Bau
Jun 08, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make xmodule_assets incremental, rather than removing the entire generated asset tree
parent
5e04b689
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
19 deletions
+39
-19
common/lib/xmodule/xmodule/static_content.py
+39
-19
No files found.
common/lib/xmodule/xmodule/static_content.py
View file @
28d666d8
...
@@ -58,7 +58,12 @@ def _ensure_dir(dir_):
...
@@ -58,7 +58,12 @@ def _ensure_dir(dir_):
def
_write_styles
(
selector
,
output_root
,
classes
):
def
_write_styles
(
selector
,
output_root
,
classes
):
_ensure_dir
(
output_root
)
"""
Write the css fragments from all XModules in `classes`
into `output_root` as individual files, hashed by the contents to remove
duplicates
"""
contents
=
{}
css_fragments
=
defaultdict
(
set
)
css_fragments
=
defaultdict
(
set
)
for
class_
in
classes
:
for
class_
in
classes
:
...
@@ -73,25 +78,34 @@ def _write_styles(selector, output_root, classes):
...
@@ -73,25 +78,34 @@ def _write_styles(selector, output_root, classes):
hash
=
hashlib
.
md5
(
fragment
)
.
hexdigest
(),
hash
=
hashlib
.
md5
(
fragment
)
.
hexdigest
(),
type
=
filetype
)
type
=
filetype
)
# Prepend _ so that sass just includes the files into a single file
# Prepend _ so that sass just includes the files into a single file
with
open
(
output_root
/
'_'
+
fragment_name
,
'w'
)
as
css_file
:
filename
=
'_'
+
fragment_name
css_file
.
write
(
fragment
)
contents
[
filename
]
=
fragment
for
class_
in
classes
:
for
class_
in
classes
:
css_imports
[
class_
]
.
add
(
fragment_name
)
css_imports
[
class_
]
.
add
(
fragment_name
)
with
open
(
output_root
/
'_module-styles.scss'
,
'w'
)
as
module_styles
:
module_styles_lines
=
[]
module_styles_lines
.
append
(
"@import 'bourbon/bourbon';"
)
module_styles_lines
.
append
(
"@import 'bourbon/addons/button';"
)
for
class_
,
fragment_names
in
css_imports
.
items
():
module_styles_lines
.
append
(
"""{selector}.xmodule_{class_} {{"""
.
format
(
class_
=
class_
,
selector
=
selector
))
module_styles_lines
.
extend
(
' @import "{0}";'
.
format
(
name
)
for
name
in
fragment_names
)
module_styles_lines
.
append
(
'}'
)
module_styles
.
write
(
"@import 'bourbon/bourbon';
\n
"
)
contents
[
'_module-styles.scss'
]
=
'
\n
'
.
join
(
module_styles_lines
)
module_styles
.
write
(
"@import 'bourbon/addons/button';
\n
"
)
for
class_
,
fragment_names
in
css_imports
.
items
():
_write_files
(
output_root
,
contents
)
imports
=
"
\n
"
.
join
(
'@import "{0}";'
.
format
(
name
)
for
name
in
fragment_names
)
module_styles
.
write
(
"""{selector}.xmodule_{class_} {{ {imports} }}
\n
"""
.
format
(
class_
=
class_
,
imports
=
imports
,
selector
=
selector
))
def
_write_js
(
output_root
,
classes
):
def
_write_js
(
output_root
,
classes
):
_ensure_dir
(
output_root
)
"""
Write the javascript fragments from all XModules in `classes`
into `output_root` as individual files, hashed by the contents to remove
duplicates
"""
contents
=
{}
js_fragments
=
set
()
js_fragments
=
set
()
for
class_
in
classes
:
for
class_
in
classes
:
...
@@ -100,18 +114,25 @@ def _write_js(output_root, classes):
...
@@ -100,18 +114,25 @@ def _write_js(output_root, classes):
for
idx
,
fragment
in
enumerate
(
module_js
.
get
(
filetype
,
[])):
for
idx
,
fragment
in
enumerate
(
module_js
.
get
(
filetype
,
[])):
js_fragments
.
add
((
idx
,
filetype
,
fragment
))
js_fragments
.
add
((
idx
,
filetype
,
fragment
))
module_js
=
[]
for
idx
,
filetype
,
fragment
in
sorted
(
js_fragments
):
for
idx
,
filetype
,
fragment
in
sorted
(
js_fragments
):
path
=
output_root
/
"{idx:0=3d}-{hash}.{type}"
.
format
(
filename
=
"{idx:0=3d}-{hash}.{type}"
.
format
(
idx
=
idx
,
idx
=
idx
,
hash
=
hashlib
.
md5
(
fragment
)
.
hexdigest
(),
hash
=
hashlib
.
md5
(
fragment
)
.
hexdigest
(),
type
=
filetype
)
type
=
filetype
)
with
open
(
path
,
'w'
)
as
js_file
:
contents
[
filename
]
=
fragment
js_file
.
write
(
fragment
)
_write_files
(
output_root
,
contents
)
return
[
output_root
/
filename
for
filename
in
contents
.
keys
()]
module_js
.
append
(
path
)
return
module_js
def
_write_files
(
output_root
,
contents
):
_ensure_dir
(
output_root
)
for
extra_file
in
set
(
output_root
.
files
())
-
set
(
contents
.
keys
()):
extra_file
.
remove
()
for
filename
,
file_content
in
contents
.
iteritems
():
(
output_root
/
filename
)
.
write_bytes
(
file_content
)
def
main
():
def
main
():
...
@@ -122,7 +143,6 @@ def main():
...
@@ -122,7 +143,6 @@ def main():
args
=
docopt
(
main
.
__doc__
)
args
=
docopt
(
main
.
__doc__
)
root
=
path
(
args
[
'<output_root>'
])
root
=
path
(
args
[
'<output_root>'
])
root
.
rmtree
(
ignore_errors
=
True
)
write_descriptor_js
(
root
/
'descriptors/js'
)
write_descriptor_js
(
root
/
'descriptors/js'
)
write_descriptor_styles
(
root
/
'descriptors/css'
)
write_descriptor_styles
(
root
/
'descriptors/css'
)
write_module_js
(
root
/
'modules/js'
)
write_module_js
(
root
/
'modules/js'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment